mdarby (owner)

Revisions

gist: 61509 Download_button fork
public
Public Clone URL: git://gist.github.com/61509.git
Embed All Files: show embed
Diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
diff --git a/app/helpers/submittals_helper.rb b/app/helpers/submittals_helper.rb
index 75ed617..e09b039 100755
--- a/app/helpers/submittals_helper.rb
+++ b/app/helpers/submittals_helper.rb
@@ -1,2 +1,11 @@
 module SubmittalsHelper
+
+ def owner_review_status(submittal)
+ if submittal.owner_reviewed?
+ "Reviewed by #{submittal.reviewing_owner.display_name} on #{submittal.owner_reviewed_at}"
+ else
+ "An Authorized Owner has yet to review this Submittal"
+ end
+ end
+
 end
diff --git a/app/models/job.rb b/app/models/job.rb
index ea3a30d..77e3dc7 100755
--- a/app/models/job.rb
+++ b/app/models/job.rb
@@ -528,6 +528,11 @@ class Job < ActiveRecord::Base
     !child_number.nil?
   end
 
+ # See if this Job has any assigned Authorized Owners
+ def has_authorized_owner?
+ @val ||= assigned_users.any?{|u| u.is_a?(AuthorizedOwner)}
+ end
+
 
   protected
 
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 7676eae..9031680 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -1,5 +1,5 @@
 # == Schema Information
-# Schema version: 20090109155322
+# Schema version: 20090210165710
 #
 # Table name: polls
 #
@@ -8,6 +8,7 @@
 # description :text
 # options :text
 # ends_at :date
+# string :text
 # created_at :datetime
 # updated_at :datetime
 # created_by_id :integer(4)
@@ -132,4 +133,4 @@ class Poll < ActiveRecord::Base
     total_votes > 0
   end
   
-end
\ No newline at end of file
+end
diff --git a/app/models/submittal.rb b/app/models/submittal.rb
index 6786833..93ae695 100755
--- a/app/models/submittal.rb
+++ b/app/models/submittal.rb
@@ -1,5 +1,5 @@
 # == Schema Information
-# Schema version: 20081202211758
+# Schema version: 20090210165710
 #
 # Table name: submittals
 #
@@ -17,6 +17,8 @@
 # reviewed_by_id :integer(4)
 # reviewed_at :datetime
 # delivered_to_id :integer(4)
+# owner_reviewed_at :datetime
+# reviewing_owner_id :integer(4)
 #
 
 class Submittal < ActiveRecord::Base
@@ -32,6 +34,7 @@ class Submittal < ActiveRecord::Base
   belongs_to :receiver, :foreign_key => 'delivered_to_id', :class_name => 'User'
   belongs_to :design_professional, :foreign_key => 'design_professional_id', :class_name => 'User'
   belongs_to :reviewing_engineer, :foreign_key => 'reviewed_by_id', :class_name => 'User'
+ belongs_to :reviewing_owner, :foreign_key => 'reviewing_owner_id', :class_name => 'User'
   belongs_to :author, :foreign_key => 'created_by_id', :class_name => 'User'
   belongs_to :spec_section
 
@@ -157,6 +160,14 @@ class Submittal < ActiveRecord::Base
     all(:include => [:response], :conditions => ["design_professional_id = ?", user.id]).select{|r| r.is_open?}
   end
   
+ def owner_reviewed?
+ owner_reviewed_at != nil
+ end
+
+ def owner_reviewable?(user)
+ (user.is_a?(AuthorizedOwner) || user.is_admin?) && !owner_reviewed?
+ end
+
   
   protected
   
diff --git a/app/views/submittals/_submittal.html.haml b/app/views/submittals/_submittal.html.haml
index 59dadb0..ba6da3d 100755
--- a/app/views/submittals/_submittal.html.haml
+++ b/app/views/submittals/_submittal.html.haml
@@ -4,6 +4,9 @@
   %td.capitalize= h truncate(submittal.spec_section.name, :length => 25)
   %td= submittal.response.name if submittal.response
   
+ - if @job.has_authorized_owner?
+ %td= submittal.owner_reviewed? ? "Reviewed" : ""
+
   - if @current_user.is_employee?
     %td= submittal.receiver.display_name rescue ""
   
diff --git a/app/views/submittals/index.html.haml b/app/views/submittals/index.html.haml
index 21d65db..2e5da87 100755
--- a/app/views/submittals/index.html.haml
+++ b/app/views/submittals/index.html.haml
@@ -9,22 +9,25 @@
 %table#sortable.sortable
   %thead
     %tr
- %th== Name
- %th== Discipline
- %th== Spec Section
- %th== Status
+ %th Name
+ %th Discipline
+ %th Spec Section
+ %th Engineer Status
+
+ - if @job.has_authorized_owner?
+ %th Owner Status
       
       - if @current_user.is_employee?
- %th== Receiver
+ %th Receiver
       
- %th== Reviewer
- %th== Received
+ %th Reviewer
+ %th Received
       
       - if @current_user.is_employee?
- %th== Due
+ %th Due
       
- %th== Returned
- %th== Days<br/>Open
+ %th Returned
+ %th Days<br/>Open
       
   %tbody#submittal_list
     = render :partial => 'submittal', :collection => @submittals
\ No newline at end of file
diff --git a/app/views/submittals/show.html.haml b/app/views/submittals/show.html.haml
index 0b60663..9f7f47a 100755
--- a/app/views/submittals/show.html.haml
+++ b/app/views/submittals/show.html.haml
@@ -9,10 +9,13 @@
   - if @submittal.is_respondable_by(@current_user)
     = link_to_function 'Respond', toggle('response_div')
 
+ - if @submittal.owner_reviewable?(@current_user)
+ = link_to 'Mark as Reviewed', owner_review_job_submittal_path(@job, @submittal)
+
 - if @submittal.is_respondable_by(@current_user)
   #response_div{ :style => "display: none;" }
     = render :partial => 'submittal_responses/new'
-
+
 
 = box("Name:") do
   = h @submittal.display_short_name
@@ -58,6 +61,12 @@
   = render :partial => 'comments/index', :locals => {:obj => @submittal}
 
 
+- if @job.has_authorized_owner?
+ .subsection_header Owner Review:
+ = box do
+ = owner_review_status(@submittal)
+
+
 - if @submittal.response
   .subsection_header== Response:
   = box do
@@ -68,6 +77,6 @@
 
 
 - if @submittal.has_been_reviewed?
- .subsection_header== Review
+ .subsection_header== Review
   = box("Review Status:") do
- = h @submittal.review_status
\ No newline at end of file
+ = h @submittal.review_status
diff --git a/db/migrate/20090210165710_add_owner_reviewed_flag_to_submittals.rb b/db/migrate/20090210165710_add_owner_reviewed_flag_to_submittals.rb
new file mode 100644
index 0000000..cf4b496
--- /dev/null
+++ b/db/migrate/20090210165710_add_owner_reviewed_flag_to_submittals.rb
@@ -0,0 +1,11 @@
+class AddOwnerReviewedFlagToSubmittals < ActiveRecord::Migration
+ def self.up
+ add_column :submittals, :owner_reviewed_at, :datetime
+ add_column :submittals, :reviewing_owner_id, :integer
+ end
+
+ def self.down
+ remove_column :submittals, :reviewing_owner_id
+ remove_column :submittals, :owner_reviewed_at
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index acffdf8..8ec70a0 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20090209181517) do
+ActiveRecord::Schema.define(:version => 20090210165710) do
 
   create_table "announcements", :force => true do |t|
     t.string "message"
@@ -826,6 +826,8 @@ ActiveRecord::Schema.define(:version => 20090209181517) do
     t.integer "reviewed_by_id"
     t.datetime "reviewed_at"
     t.integer "delivered_to_id"
+ t.datetime "owner_reviewed_at"
+ t.integer "reviewing_owner_id"
   end
 
   add_index "submittals", ["design_professional_id"], :name => "index_submittals_on_design_professional_id"
diff --git a/spec/helpers/submittals_helper_spec.rb b/spec/helpers/submittals_helper_spec.rb
index 4cc2013..bb559a4 100755
--- a/spec/helpers/submittals_helper_spec.rb
+++ b/spec/helpers/submittals_helper_spec.rb
@@ -2,5 +2,22 @@ require File.dirname(__FILE__) + '/../spec_helper'
 
 describe SubmittalsHelper do
 
+ describe " -- the owner_review_status method" do
+ describe "when the submittal has been reviewd" do
+ it "should show this blurb" do
+ user = mock_model(User, :display_name => "foo bar")
+ submittal = mock_model(Submittal, :owner_reviewed? => true, :reviewing_owner => user, :owner_reviewed_at => Date.today)
+ helper.owner_review_status(submittal).should == "Reviewed by #{submittal.reviewing_owner.display_name} on #{submittal.owner_reviewed_at}"
+ end
+ end
+
+ describe "when the submittal has not been reviewed" do
+ it "should show this blurb" do
+ submittal = mock_model(Submittal, :owner_reviewed? => false)
+ helper.owner_review_status(submittal).should == "An Authorized Owner has yet to review this Submittal"
+ end
+ end
+
+ end
   
-end
+end
\ No newline at end of file
diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb
index d9afd97..24fd9ee 100755
--- a/spec/models/job_spec.rb
+++ b/spec/models/job_spec.rb
@@ -231,6 +231,13 @@ describe "Job" do
     @job.is_subjob?.should be_false
   end
   
+ it "should know if it has any assigned Authorized Owners" do
+ user_1 = mock_model(AuthorizedOwner)
+ user_2 = mock_model(HvacEngineer)
+ @job.stub!(:assigned_users => [user_1, user_2])
+ @job.has_authorized_owner?.should be_true
+ end
+
   
   describe " - Subjob" do
     before do
diff --git a/spec/models/submittal_spec.rb b/spec/models/submittal_spec.rb
index 7af55ac..b15de84 100755
--- a/spec/models/submittal_spec.rb
+++ b/spec/models/submittal_spec.rb
@@ -34,6 +34,10 @@ describe "A Submittal" do
     @submittal.should be_valid
   end
   
+ it "should respond to :reviewing_owner" do
+ @submittal.should respond_to(:reviewing_owner)
+ end
+
   it "should have a name" do
     @submittal.name = nil
     @submittal.should_not be_valid
@@ -223,4 +227,45 @@ describe "A Submittal" do
     end
   end
 
+ describe " in a Job with an Authorized Owner" do
+ describe "without an existing owner review" do
+ before do
+ @submittal.stub!(:owner_reviewed? => false)
+ end
+
+ it "should be owner reviewable by an Authorized Owner" do
+ @submittal.owner_reviewable?(@authed_owner).should be_true
+ end
+
+ it "should not be reviewable by anyone else" do
+ @submittal.owner_reviewable?(@user).should be_false
+ @submittal.owner_reviewable?(@employee).should be_false
+ end
+
+ it "should know that it hasn't been reviewed" do
+ @submittal.owner_reviewed?.should be_false
+ end
+ end
+
+ describe "with an existing owner review" do
+ before do
+ @submittal.stub!(:owner_reviewed_at => Date.today, :reviewing_owner => @authed_owner)
+ end
+
+ it "should not be reviewable by an Authorized Owner" do
+ @submittal.owner_reviewable?(@authed_owner).should be_false
+ end
+
+ it "should know that it has been reviewed" do
+ @submittal.owner_reviewed?.should be_true
+ end
+ end
+ end
+
+ describe " in a Job without an Authorized Owner" do
+ it "should not allow owner reviews" do
+ @submittal.owner_reviewable?(@employee).should be_false
+ end
+ end
+
 end
\ No newline at end of file
diff --git a/spec/views/submittals/_submittal.html.haml_spec.rb b/spec/views/submittals/_submittal.html.haml_spec.rb
index 0fa58c6..a642d3c 100644
--- a/spec/views/submittals/_submittal.html.haml_spec.rb
+++ b/spec/views/submittals/_submittal.html.haml_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
 describe "/submittals/_submittal.html.haml" do
   
   before do
- @job = mock_model(Job, :is_fasttrack? => false, :bulletins => [], :submittals => [])
+ @job = mock_model(Job, :is_fasttrack? => false, :bulletins => [], :submittals => [], :has_authorized_owner? => false)
     @spec_section = mock_model(SpecSection, :name => "foo")
     @sub_response = mock_model(SubmittalResponse, :name => "foo", :created_at => Time.now)
     
@@ -119,4 +119,16 @@ describe "/submittals/_submittal.html.haml" do
     end
   end
     
+ describe " with a Job that has an Authorized Owner" do
+ before do
+ @job.stub!(:has_authorized_owner? => true)
+ @submittal.stub!(:owner_reviewed? => true)
+ end
+
+ it "should show the owner review table cell" do
+ do_get
+ response.should have_tag("td", "Reviewed")
+ end
+ end
+
 end
\ No newline at end of file
diff --git a/spec/views/submittals/index.html.haml_spec.rb b/spec/views/submittals/index.html.haml_spec.rb
index ea7a945..f22fba7 100644
--- a/spec/views/submittals/index.html.haml_spec.rb
+++ b/spec/views/submittals/index.html.haml_spec.rb
@@ -5,17 +5,18 @@ describe "/submittals/index.html.haml" do
   it_should_behave_like "it has the job_nav"
     
   before do
- @job = mock_model(Job, :submittals => [])
+ @job = mock_model(Job, :submittals => [], :has_authorized_owner? => false)
     @job.stub!(:submittals => [])
     @job.stub!(:plain_display_name => "foo")
     @job.stub!(:is_fasttrack? => false)
     @job.stub!(:bulletins => [])
     
     @submittal = Factory(:submittal, :job => @job)
- @employee = mock_model(User, :is_employee? => true)
+ @user = mock_model(User, :is_employee? => false)
     
     assigns[:job] = @job
     assigns[:submittals] = [@submittal]
+ assigns[:current_user] = @user
     
     template.stub!(:render).with(:partial => "submittal", :collection => [@submittal])
     template.stub!(:creatable => false)
@@ -28,7 +29,7 @@ describe "/submittals/index.html.haml" do
   
   describe " when an employee is logged in" do
     before do
- assigns[:current_user].stub!(:is_employee? => true)
+ @user.stub!(:is_employee? => true)
     end
     
     it "should have a sortable table" do
@@ -43,7 +44,7 @@ describe "/submittals/index.html.haml" do
         with_tag("th", "Name")
         with_tag("th", "Discipline")
         with_tag("th", "Spec Section")
- with_tag("th", "Status")
+ with_tag("th", "Engineer Status")
         with_tag("th", "Receiver")
         with_tag("th", "Reviewer")
         with_tag("th", "Received")
@@ -56,7 +57,7 @@ describe "/submittals/index.html.haml" do
   
   describe " when a non-employee is logged in" do
     before do
- assigns[:current_user].stub!(:is_employee? => false)
+ @user.stub!(:is_employee? => false)
     end
     
     it "should have a sortable table sans the Receiver & Due columns" do
@@ -66,7 +67,7 @@ describe "/submittals/index.html.haml" do
         with_tag("th", "Name")
         with_tag("th", "Discipline")
         with_tag("th", "Spec Section")
- with_tag("th", "Status")
+ with_tag("th", "Engineer Status")
         with_tag("th", "Reviewer")
         with_tag("th", "Received")
         with_tag("th", "Returned")
@@ -75,4 +76,15 @@ describe "/submittals/index.html.haml" do
     end
   end
   
+ describe " in a Job that has an Authorized Owner" do
+ before do
+ @job.stub!(:has_authorized_owner? => true)
+ end
+
+ it "should the owner review table header" do
+ do_get
+ response.should have_tag("th", "Owner Status")
+ end
+ end
+
 end
\ No newline at end of file
diff --git a/spec/views/submittals/show.html.haml_spec.rb b/spec/views/submittals/show.html.haml_spec.rb
index 993ea4b..ed351f5 100644
--- a/spec/views/submittals/show.html.haml_spec.rb
+++ b/spec/views/submittals/show.html.haml_spec.rb
@@ -17,6 +17,9 @@ describe "/submittals/show.html.haml" do
     @submittal.stub!(:response => nil)
     @submittal.stub!(:is_updatable_by => false)
     @submittal.stub!(:has_been_reviewed? => false)
+ @submittal.stub!(:owner_reviewable? => false)
+
+ @job.stub!(:has_authorized_owner? => false)
     
     assigns[:job] = @job
     assigns[:submittal] = @submittal
@@ -25,6 +28,7 @@ describe "/submittals/show.html.haml" do
     assigns[:current_user].stub!(:is_admin? => false)
     assigns[:current_user].stub!(:is_tim_allen? => false)
     
+ template.stub!(:owner_review_status)
     template.stub!(:render).with(:partial => "submittal_responses/new")
     template.stub!(:render).with(:partial => "attachments/index", :locals => {:obj => @submittal})
     template.stub!(:render).with(:partial => "comments/index", :locals => {:obj => @submittal})
@@ -172,4 +176,44 @@ describe "/submittals/show.html.haml" do
 
   end
   
+ describe "in a Job with an Authorized Owner" do
+ before do
+ @job.stub!(:has_authorized_owner? => true)
+ end
+
+ it "should shwo the Owner Review subsection" do
+ do_get
+ response.should have_tag("div[class=?]", "subsection_header")
+ end
+
+ it "should call the #owner_review_status helper" do
+ template.should_receive(:owner_review_status).with(@submittal)
+ do_get
+ end
+
+
+ describe " that has yet to be reviewed" do
+ before do
+ @submittal.stub!(:owner_reviewable? => true)
+ end
+
+ it "should show a review link" do
+ do_get
+ response.should have_tag("a[href=?]", owner_review_job_submittal_path(@job, @submittal))
+ end
+ end
+
+ describe " that has been reviewed" do
+ before do
+ @submittal.stub!(:owner_reviewable? => false)
+ end
+
+ it "should not show a review link" do
+ do_get
+ response.should_not have_tag("a[href=?]", owner_review_job_submittal_path(@job, @submittal))
+ end
+ end
+
+ end
+
 end
\ No newline at end of file