Skip to content

Commit 92a2538

Browse files
committed
WIP: Proposal review + private messages (comments).
1 parent 12eb19b commit 92a2538

File tree

10 files changed

+38
-40
lines changed

10 files changed

+38
-40
lines changed

app/assets/javascripts/concerns/form.js.coffee

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ jQuery ->
2929
parent.next().fadeIn()
3030

3131
e.preventDefault()
32-
)
32+
)
33+
34+
# read only forms
35+
$('.read_only form :input:not([type=submit])').attr('disabled', 'disabled')

app/controllers/proposals_controller.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ProposalsController < ApplicationController
44
belongs_to :startup
55

66
def create
7-
parent.submit_proposal(investors, params[:proposal], proposal_stage)
7+
parent.create_proposal(investors, params[:proposal], proposal_stage)
88
show_flash_message
99
redirect_to parent_path
1010
end
@@ -17,12 +17,6 @@ def update
1717
redirect_to parent_path
1818
end
1919

20-
def edit
21-
@investors = resource.investors.for_auto_suggest.to_json
22-
23-
edit!
24-
end
25-
2620
private
2721

2822
def investors

app/models/message.rb

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def is_private?
3232
!!is_private
3333
end
3434

35+
def is_with_proposal?
36+
!!proposal_id
37+
end
38+
39+
def is_without_proposal?
40+
!proposal_id
41+
end
42+
3543
def method_missing(symbol, *args)
3644
case symbol
3745
when /^is_(un)?(.*)\?/

app/models/startup.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,10 @@ def user_role(user)
107107
I18n.t "startup.role_identifiers.#{user_meta(user).role_identifier}"
108108
end
109109

110-
def create_proposal(attributes = {})
111-
proposals.create(attributes)
112-
end
113-
114-
def submit_proposal(investors = [], attributes = {}, stage = 'draft', private_message = I18n.t('text.default_text_for_proposal_review'))
115-
proposal = create_proposal(attributes)
110+
def create_proposal(investors = [], attributes = {}, stage = 'draft', private_message = I18n.t('text.default_text_for_proposal_review'))
111+
proposal = proposals.create(attributes)
116112
update_and_submit_proposal(proposal, investors, attributes, stage)
117-
send_private_message_to_investors(proposal, investors, private_message)
113+
send_private_message_to_investors(proposal, investors, private_message) if stage == 'submitted'
118114
proposal
119115
end
120116

app/views/messages/show_private_message.html.slim

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
.grid_9
44
ul#messages
55
li.message= render 'show', :resource => @topic, :meta => {}
6-
76
- @topic.replies.each do |reply|
87
li.message= render 'show', :resource => reply, :meta => {}
98
br
109
= render 'new', :url => my_private_message_path(@topic)
10+
- if @topic.is_with_proposal?
11+
hr
12+
h1= t('label.business_proposal')
13+
.read_only= render 'proposals/form', :resource => @topic.proposal, :submit_path => '/'

app/views/proposals/_form.html.slim

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ul#proposal_section_selector.multistage_selector
1111
legend= t('label.investors')
1212
.multi_add.input.string
1313
= label_tag :investors, t('label.investors')
14-
= text_field_tag :investors, resource.investors.map(&:id).join(','), :class => 'string required', :'data-investors' => @investors
14+
= text_field_tag :investors, resource.investors.map(&:id).join(','), :class => 'string required', :'data-investors' => resource.investors.for_auto_suggest.to_json
1515
.grouped_buttons
1616
= submit_tag t('label.next'), :class => 'navigation next'
1717
fieldset#product

db/seeds_for_dev.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
startup.attach_user(u, :member, Faker::Lorem.word)
4141
startup.confirm_user(u)
4242

43-
2.times { startup.submit_proposal(User.investors.sample, Proposal.make.attributes, 'draft') }
44-
startup.submit_proposal(User.investors.sample, Proposal.make.attributes, 'submitted', Faker::Lorem.sentence)
45-
startup.submit_proposal(user, Proposal.make.attributes, 'submitted', Faker::Lorem.sentence) if rand(5) == 0
43+
2.times { startup.create_proposal(User.investors.sample, Proposal.make.attributes, 'draft') }
44+
3.times { startup.create_proposal(User.investors.sample, Proposal.make.attributes, 'submitted', Faker::Lorem.sentence) }
45+
startup.create_proposal(user, Proposal.make.attributes, 'submitted', Faker::Lorem.sentence) if rand(5) == 0
4646
if rand(10) == 0
47-
startup.submit_proposal(user, Proposal.make.attributes, 'submitted', Faker::Lorem.sentence)
47+
startup.create_proposal(user, Proposal.make.attributes, 'submitted', Faker::Lorem.sentence)
4848
Message.last.mark_as_archived!
4949
end
5050
end

spec/controllers/proposals_controller_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
get :edit, :startup_id => startup.id,
2323
:id => proposal.id
2424

25-
assigns(:investors).should be_a(String)
26-
assigns(:investors).should == investors.for_auto_suggest.to_json
25+
response.should be_success
2726
end
2827

2928
it "submits to an investor" do

spec/models/message_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676

7777
private_message.is_private?.should == true
7878
private_message.is_public?.should == false
79+
private_message.is_with_proposal?.should == false
80+
private_message.is_without_proposal?.should == true
7981
end
8082

8183
it "adds a reply to a topic" do

spec/models/proposal_spec.rb

+10-17
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,20 @@
4141
startup.attach_user(founder, :member)
4242
end
4343

44-
it "creates a draft proposal" do
45-
startup.create_proposal(proposal.attributes)
46-
47-
startup.proposals.count.should == 1
48-
startup.proposals.draft.count.should == 1
49-
startup.proposals.submitted.count.should == 0
50-
startup.proposals.first.proposal_stage_identifier.should == 'draft'
51-
end
52-
5344
it "returns the proposal itself" do
54-
startup.submit_proposal([], proposal.attributes).should == Proposal.last
45+
startup.create_proposal([], proposal.attributes).should == Proposal.last
5546
end
5647

5748
it "submits proposal to no investor" do
58-
startup.submit_proposal([], proposal.attributes)
49+
startup.create_proposal([], proposal.attributes)
5950

6051
startup.proposals.count.should == 1
6152
startup.proposals.draft.count.should == 1
6253
startup.proposals.submitted.count.should == 0
6354
end
6455

6556
it "submits proposal to one investor" do
66-
startup.submit_proposal(investor1, proposal.attributes, 'submitted')
57+
startup.create_proposal(investor1, proposal.attributes, 'submitted')
6758

6859
startup.proposals.count.should == 1
6960
startup.proposals.draft.count.should == 0
@@ -73,10 +64,12 @@
7364
investor1.inbox_proposals.count.should == 1
7465
startup.proposals.first.proposal_stage_identifier.should == 'submitted'
7566
startup.founder.sent_proposals.first.content.should == I18n.t('text.default_text_for_proposal_review')
67+
Message.last.is_with_proposal?.should == true
68+
Message.last.is_without_proposal?.should == false
7669
end
7770

7871
it "submits proposal to many investors" do
79-
startup.submit_proposal([investor1, investor2], proposal.attributes, 'submitted', 'Hey man!')
72+
startup.create_proposal([investor1, investor2], proposal.attributes, 'submitted', 'Hey man!')
8073

8174
startup.proposals.count.should == 1
8275
startup.proposals.draft.count.should == 0
@@ -92,7 +85,7 @@
9285
end
9386

9487
it "edits a proposal" do
95-
startup.submit_proposal(investor1, proposal.attributes)
88+
startup.create_proposal(investor1, proposal.attributes)
9689
startup.update_proposal(Proposal.last, investor2, Proposal.make(:pitch => 'Hello world').attributes)
9790

9891
Proposal.last.pitch.should == 'Hello world'
@@ -105,7 +98,7 @@
10598
end
10699

107100
it "edits and submits a proposal" do
108-
startup.submit_proposal(investor1, proposal.attributes)
101+
startup.create_proposal(investor1, proposal.attributes)
109102
startup.update_proposal(Proposal.last, investor2, Proposal.make(:pitch => 'Hello world').attributes, 'submitted')
110103

111104
Proposal.last.pitch.should == 'Hello world'
@@ -118,7 +111,7 @@
118111
end
119112

120113
it "archives a proposal message" do
121-
startup.submit_proposal(investor1, proposal.attributes)
114+
startup.create_proposal(investor1, proposal.attributes, 'submitted')
122115

123116
investor1.inbox_proposals.count.should == 1
124117
investor1.archived_proposals.count.should == 0
@@ -135,7 +128,7 @@
135128

136129
it "preserves proposal details structure" do
137130
proposal_attributes = proposal.attributes.merge(:pitch => 'Hello world')
138-
startup.submit_proposal(investor1, proposal_attributes)
131+
startup.create_proposal(investor1, proposal_attributes)
139132

140133
Proposal.last.pitch.should == 'Hello world'
141134
end

0 commit comments

Comments
 (0)