naf 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/README.rdoc +28 -4
  2. data/RELEASE_NOTES.rdoc +8 -0
  3. data/app/assets/javascripts/dataTablesTemplates/application_schedules.js +72 -0
  4. data/app/assets/javascripts/dataTablesTemplates/applications.js +12 -21
  5. data/app/controllers/naf/application_schedule_affinity_tabs_controller.rb +5 -8
  6. data/app/controllers/naf/application_schedules_controller.rb +98 -0
  7. data/app/controllers/naf/applications_controller.rb +6 -98
  8. data/app/controllers/naf/historical_jobs_controller.rb +18 -8
  9. data/app/helpers/naf/application_helper.rb +47 -22
  10. data/app/models/logical/naf/application.rb +9 -126
  11. data/app/models/logical/naf/application_schedule.rb +186 -0
  12. data/app/models/logical/naf/construction_zone/boss.rb +4 -5
  13. data/app/models/logical/naf/construction_zone/foreman.rb +34 -13
  14. data/app/models/logical/naf/construction_zone/proletariat.rb +1 -0
  15. data/app/models/logical/naf/construction_zone/work_order.rb +11 -4
  16. data/app/models/logical/naf/job_fetcher.rb +1 -0
  17. data/app/models/naf/application.rb +5 -16
  18. data/app/models/naf/application_schedule.rb +117 -43
  19. data/app/models/naf/historical_job.rb +6 -3
  20. data/app/models/naf/queued_job.rb +3 -0
  21. data/app/models/naf/run_interval_style.rb +20 -0
  22. data/app/models/naf/running_job.rb +3 -0
  23. data/app/models/process/naf/data_migration/backfill_application_schedule_run_interval.rb +85 -0
  24. data/app/models/process/naf/log_archiver.rb +1 -1
  25. data/app/models/process/naf/log_reader.rb +141 -0
  26. data/app/models/process/naf/runner.rb +6 -49
  27. data/app/views/naf/application_schedule_affinity_tabs/_form.html.erb +1 -1
  28. data/app/views/naf/{applications → application_schedules}/_application_schedule_prerequisites.html.erb +1 -1
  29. data/app/views/naf/application_schedules/_form.html.erb +120 -0
  30. data/app/views/naf/application_schedules/edit.html.erb +11 -0
  31. data/app/views/naf/application_schedules/index.html.erb +47 -0
  32. data/app/views/naf/application_schedules/index.json.erb +8 -0
  33. data/app/views/naf/application_schedules/new.html.erb +11 -0
  34. data/app/views/naf/application_schedules/show.html.erb +130 -0
  35. data/app/views/naf/applications/_form.html.erb +44 -106
  36. data/app/views/naf/applications/_search_container.html.erb +29 -29
  37. data/app/views/naf/applications/index.html.erb +1 -10
  38. data/app/views/naf/applications/index.json.erb +22 -6
  39. data/app/views/naf/applications/show.html.erb +47 -97
  40. data/app/views/naf/logger_styles/_form.html.erb +0 -3
  41. data/app/views/naf/machines/_form.html.erb +3 -4
  42. data/config/routes.rb +3 -4
  43. data/db/migrate/20131219195439_add_run_interval_styles_table.rb +49 -0
  44. data/db/migrate/20140113183243_drop_run_start_minute_from_application_schedules.rb +18 -0
  45. data/lib/naf/version.rb +1 -1
  46. data/naf.gemspec +1 -1
  47. data/spec/controllers/naf/application_schedule_affinity_tabs_controller_spec.rb +34 -27
  48. data/spec/controllers/naf/applications_controller_spec.rb +0 -48
  49. data/spec/factories/naf.rb +14 -8
  50. data/spec/models/logical/naf/application_spec.rb +9 -37
  51. data/spec/models/logical/naf/machine_spec.rb +1 -1
  52. data/spec/models/naf/application_schedule_spec.rb +38 -50
  53. data/spec/models/naf/application_spec.rb +3 -3
  54. data/spec/models/naf/historical_job_spec.rb +4 -2
  55. data/spec/models/naf/queued_job_spec.rb +2 -0
  56. data/spec/models/naf/run_interval_style_spec.rb +28 -0
  57. data/spec/models/naf/running_job_spec.rb +2 -0
  58. metadata +19 -7
  59. data/app/models/logical/naf/job_creator.rb +0 -151
  60. data/app/views/naf/applications/_application_schedule.html.erb +0 -80
  61. data/spec/models/logical/naf/job_creator_spec.rb +0 -102
@@ -1,11 +1,27 @@
1
1
  <%
2
2
  rows = @applications.each do |application|
3
- app = Naf::Application.find(application.first)
4
- application.insert(10, naf_last_queued_at_link(app))
5
- application.insert(13,(link_to image_tag('control_play_blue.png',
6
- class: 'action',
7
- title: "Enqueue Application(\nid: #{app.id},\ntitle: #{app.title},\ncommand: #{app.command})"),
8
- "#", { class: "enqueue", id: application[0] }))
3
+ app = Naf::Application.find(application.first)
4
+ schedules = application[4]
5
+ application[4] = ''
6
+ schedules.each do |schedule|
7
+ logical_schedule = ::Logical::Naf::ApplicationSchedule.new(schedule)
8
+ if application[4].present?
9
+ application[4] << (link_to logical_schedule.display,
10
+ application_schedule_path(schedule.id),
11
+ title: logical_schedule.help_title)
12
+ else
13
+ application[4] = (link_to logical_schedule.display,
14
+ application_schedule_path(schedule.id),
15
+ title: logical_schedule.help_title)
16
+ end
17
+ application[4] << ", ".html_safe
18
+ end
19
+ application[4] = application[4][0..-3]
20
+ application.insert(5, naf_last_queued_at_link(app))
21
+ application.insert(6,(link_to image_tag('control_play_blue.png',
22
+ class: 'action',
23
+ title: "Enqueue Application(\nid: #{app.id},\ntitle: #{app.title},\ncommand: #{app.command})"),
24
+ "#", { class: "enqueue", id: application[0] }))
9
25
  end
10
26
  %>
11
27
  <%= raw rows %>
@@ -1,37 +1,38 @@
1
1
  <% content_for :body do %>
2
2
  <div id="flash_message">
3
- <% unless notice.blank? %>
4
- <script type='text/javascript'>
5
- jQuery("<p id='notice'><%= notice %></p>")
6
- .appendTo('#flash_message')
7
- .slideDown().delay(5000).slideUp();
8
- </script>
9
- <% end %>
3
+ <% unless notice.blank? %>
4
+ <script type='text/javascript'>
5
+ jQuery("<p id='notice'><%= notice %></p>")
6
+ .appendTo('#flash_message')
7
+ .slideDown().delay(5000).slideUp();
8
+ </script>
9
+ <% end %>
10
10
  </div>
11
11
 
12
12
  <% content_for :javascripts do %>
13
13
  <script type='text/javascript'>
14
- jQuery(document).ready(function () {
15
- jQuery(document).delegate('.enqueue', "click", function(){
16
- var postSource = "<%= naf.historical_jobs_path %>";
17
- var answer = confirm("Adding application as a job on the queue?");
18
- if (!answer) {
19
- return false;
20
- }
21
- jQuery.post(postSource, { "historical_job[application_id]":jQuery(this).attr('id') }, function (data) {
22
- if (data.success) {
23
- jQuery("<p id='notice'>Congratulations, a Job " + data.title + " was added!</p>").
24
- appendTo('#flash_message').slideDown().delay(5000).slideUp();
25
- setTimeout('window.location.reload()', 5600);
26
- }
27
- else {
28
- jQuery("<div class='error'>Sorry, \'" + data.title + "\' cannot add a Job to the queue right now!</div>").
29
- appendTo('#flash_message').slideDown().delay(5000).slideUp();
30
- jQuery('#datatable').dataTable().fnDraw();
31
- }
32
- });
33
- });
14
+ jQuery(document).ready(function () {
15
+ jQuery(document).delegate('.enqueue', "click", function(){
16
+ var postSource = "<%= naf.historical_jobs_path %>";
17
+ var answer = confirm("Adding application as a job on the queue?");
18
+ if (!answer) {
19
+ return false;
20
+ }
21
+ jQuery.post(postSource, { "historical_job[application_id]":jQuery(this).attr('id') }, function (data) {
22
+ if (data.success) {
23
+ jQuery("<p id='notice'>Congratulations, a Job " + data.title + " was added!</p>").
24
+ appendTo('#flash_message').slideDown().delay(5000).slideUp();
25
+ setTimeout('window.location.reload()', 5600);
26
+ }
27
+ else {
28
+ jQuery("<div class='error'>Sorry, \'" + data.title +
29
+ "\' cannot add a Job to the queue right now!</div>").
30
+ appendTo('#flash_message').slideDown().delay(5000).slideUp();
31
+ jQuery('#datatable').dataTable().fnDraw();
32
+ }
33
+ });
34
34
  });
35
+ });
35
36
  </script>
36
37
  <% end %>
37
38
 
@@ -40,10 +41,10 @@
40
41
  <%= link_to 'Back to Applications', applications_path %>
41
42
  &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
42
43
  <%= link_to 'Edit', edit_application_path(@application) %>
43
- <% if @application.application_schedule.present? -%>
44
- &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
45
- <%= link_to "Add Affinity", new_application_application_schedule_application_schedule_affinity_tab_path(@application, @application.application_schedule) %>
46
- <% end -%>
44
+ &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
45
+ <%= link_to "Add Schedule", controller: 'application_schedules',
46
+ action: 'new',
47
+ application_id: @application.id %>
47
48
  </br>
48
49
  </br>
49
50
 
@@ -95,56 +96,26 @@
95
96
  <td>Script Type Name</td>
96
97
  <td><%= @logical_application.script_type_name %></td>
97
98
  </tr>
98
- <% if @application.application_schedule.present? %>
99
- <tr>
100
- <td>Application Run Group Name</td>
101
- <td style="white-space: pre-wrap;"><%= @logical_application.application_run_group_name %></td>
102
- </tr>
103
- <tr>
104
- <td>Application Run Group Limit</td>
105
- <td><%= @application.application_schedule.application_run_group_limit %></td>
106
- </tr>
107
- <tr>
108
- <td>Application Run Group Restriction Name</td>
109
- <td><%= @logical_application.application_run_group_restriction_name %></td>
110
- </tr>
111
- <tr>
112
- <td>Run Interval</td>
113
- <td><%= @logical_application.run_interval %></td>
114
- </tr>
115
- <tr>
116
- <td>Run Start Minute</td>
117
- <td><%= @logical_application.run_start_minute %></td>
118
- </tr>
119
- <tr>
120
- <td>Priority</td>
121
- <td><%= @logical_application.priority %></td>
122
- </tr>
123
- <tr>
124
- <td>Visible</td>
125
- <td><%= @logical_application.visible %></td>
126
- </tr>
127
- <tr>
128
- <td>Enabled</td>
129
- <td><%= @logical_application.enabled %></td>
130
- </tr>
131
- <tr>
132
- <td>Enqueue Backlogs</td>
133
- <td><%= @logical_application.enqueue_backlogs %></td>
134
- </tr>
135
- <tr>
136
- <td><%= link_to "Application Schedule Affinity Tabs",
137
- application_application_schedule_application_schedule_affinity_tabs_path(@application, @application.application_schedule) %>
138
- </td>
139
- <td><%= @logical_application.affinities %></td>
140
- </tr>
141
- <% end %>
99
+ <tr>
100
+ <td>Application Schedules</td>
101
+ <td>
102
+ <% output = '' %>
103
+ <% @logical_application.application_schedules.each do |schedule|
104
+ logical_schedule = ::Logical::Naf::ApplicationSchedule.new(schedule)
105
+ output << (link_to logical_schedule.display, naf.application_schedule_path(schedule.id))
106
+ output << ', '
107
+ end
108
+ output = output[0..-3] %>
109
+ <%= output.html_safe %>
110
+ </td>
111
+ </tr>
142
112
  <tr>
143
113
  <td>Add Script to Jobs Queue</td>
144
114
  <td>
145
115
  <%= link_to image_tag('control_play_blue.png',
146
116
  class: 'action',
147
- title: "Enqueue Application(\nid: #{@application.id},\ntitle: #{@application.title},\ncommand: #{@application.command})"),
117
+ title: "Enqueue Application(\nid: #{@application.id},\n" +
118
+ "title: #{@application.title},\ncommand: #{@application.command})"),
148
119
  "#", { class: "enqueue", id: @application.id } %>
149
120
  </td>
150
121
  </tr>
@@ -152,27 +123,6 @@
152
123
  </table>
153
124
  </br>
154
125
 
155
- <% if @application.application_schedule.present? %>
156
- <h2>Prerequisites</h2>
157
- <table id="naf_table_show">
158
- <thead>
159
- <tr>
160
- <th width="10%">ID</th>
161
- <th>Command</th>
162
- </tr>
163
- </thead>
164
- <tbody>
165
- <% @application.application_schedule.application_schedule_prerequisites.each do |prereq| -%>
166
- <tr>
167
- <td><%= link_to prereq.prerequisite_application_schedule.id, application_path(prereq.prerequisite_application_schedule.application) %></td>
168
- <td style="white-space: pre-wrap;"><%= prereq.prerequisite_application_schedule.application.command %></td>
169
- </tr>
170
- <% end -%>
171
- </tbody>
172
- </table>
173
- </br>
174
- <% end %>
175
-
176
126
  <h2>Last Queued Job</h2>
177
127
  <table id="naf_table_show">
178
128
  <thead>
@@ -17,11 +17,8 @@
17
17
  </div>
18
18
  </br>
19
19
 
20
-
21
20
  <%= naf_link_to_add_fields "Add the following pair of Name - Level", f, :logger_style_names %>
22
21
 
23
-
24
-
25
22
  <br>
26
23
  <br />
27
24
  <div class="actions">
@@ -1,9 +1,8 @@
1
1
  <%= form_for(@machine) do |f| %>
2
-
3
2
  <% if @machine.errors.any? %>
4
- <div id="errorExplanation">
5
- <h2><%= pluralize(@machine.errors.count, "error") %> prohibited machine from being saved:</h2>
6
- </div>
3
+ <div id="errorExplanation">
4
+ <h2><%= pluralize(@machine.errors.count, "error") %> prohibited machine from being saved:</h2>
5
+ </div>
7
6
  <% end %>
8
7
  </br>
9
8
 
data/config/routes.rb CHANGED
@@ -3,10 +3,9 @@ Naf::Engine.routes.draw do
3
3
  resources :historical_job_affinity_tabs, except: [:destroy]
4
4
  end
5
5
 
6
- resources :applications, except: [:destroy] do
7
- resources :application_schedules, only: [] do
8
- resources :application_schedule_affinity_tabs
9
- end
6
+ resources :applications, except: [:destroy]
7
+ resources :application_schedules do
8
+ resources :application_schedule_affinity_tabs
10
9
  end
11
10
 
12
11
  resources :machines, except: [:destroy] do
@@ -0,0 +1,49 @@
1
+ class AddRunIntervalStylesTable < ActiveRecord::Migration
2
+ def up
3
+ execute <<-SQL
4
+ CREATE TABLE #{Naf.schema_name}.run_interval_styles
5
+ (
6
+ id SERIAL NOT NULL PRIMARY KEY,
7
+ created_at TIMESTAMP NOT NULL default now(),
8
+ name TEXT NOT NULL
9
+ );
10
+
11
+ INSERT INTO #{Naf.schema_name}.run_interval_styles (name)
12
+ VALUES ('at beginning of day'), ('at beginning of hour'), ('after previous run'), ('keep running');
13
+
14
+ ALTER TABLE #{Naf.schema_name}.application_schedules
15
+ ADD COLUMN run_interval_style_id INTEGER NULL REFERENCES #{Naf.schema_name}.run_interval_styles;
16
+ ALTER TABLE #{Naf.schema_name}.application_schedules ADD COLUMN application_run_group_quantum INTEGER NULL;
17
+ ALTER TABLE #{Naf.schema_name}.application_schedules
18
+ DROP CONSTRAINT application_schedules_check1;
19
+ DROP INDEX #{Naf.schema_name}.applications_have_one_schedule_udx ;
20
+ ALTER TABLE #{Naf.schema_name}.application_schedules
21
+ DROP CONSTRAINT application_schedules_application_id_key;
22
+
23
+ ALTER TABLE #{Naf.schema_name}.historical_jobs
24
+ ADD COLUMN application_schedule_id INTEGER NULL REFERENCES #{Naf.schema_name}.application_schedules;
25
+ ALTER TABLE #{Naf.schema_name}.running_jobs
26
+ ADD COLUMN application_schedule_id INTEGER NULL REFERENCES #{Naf.schema_name}.application_schedules;
27
+ ALTER TABLE #{Naf.schema_name}.queued_jobs
28
+ ADD COLUMN application_schedule_id INTEGER NULL REFERENCES #{Naf.schema_name}.application_schedules;
29
+ SQL
30
+ end
31
+
32
+ def down
33
+ execute <<-SQL
34
+ ALTER TABLE #{Naf.schema_name}.queued_jobs DROP COLUMN application_schedule_id;
35
+ ALTER TABLE #{Naf.schema_name}.running_jobs DROP COLUMN application_schedule_id;
36
+ ALTER TABLE #{Naf.schema_name}.historical_jobs DROP COLUMN application_schedule_id;
37
+
38
+ ALTER TABLE #{Naf.schema_name}.application_schedules
39
+ ADD CONSTRAINT application_schedules_application_id_key UNIQUE (application_id);
40
+ CREATE UNIQUE INDEX applications_have_one_schedule_udx
41
+ ON #{Naf.schema_name}.application_schedules (application_id) WHERE enabled = true;
42
+ ALTER TABLE #{Naf.schema_name}.application_schedules ADD CONSTRAINT application_schedules_check1
43
+ CHECK (run_start_minute IS NULL OR run_interval IS NULL);
44
+ ALTER TABLE #{Naf.schema_name}.application_schedules DROP COLUMN application_run_group_quantum;
45
+ ALTER TABLE #{Naf.schema_name}.application_schedules DROP COLUMN run_interval_style_id;
46
+ DROP TABLE #{Naf.schema_name}.run_interval_styles;
47
+ SQL
48
+ end
49
+ end
@@ -0,0 +1,18 @@
1
+ class DropRunStartMinuteFromApplicationSchedules < ActiveRecord::Migration
2
+ def up
3
+ execute <<-SQL
4
+ ALTER TABLE #{Naf.schema_name}.application_schedules DROP COLUMN run_start_minute;
5
+ ALTER TABLE #{Naf.schema_name}.application_schedules ALTER COLUMN run_interval SET NOT NULL;
6
+ ALTER TABLE #{Naf.schema_name}.application_schedules ALTER COLUMN run_interval_style_id SET NOT NULL;
7
+ SQL
8
+ end
9
+
10
+ def down
11
+ execute <<-SQL
12
+ ALTER TABLE #{Naf.schema_name}.application_schedules ADD COLUMN run_start_minute INTEGER NULL
13
+ CHECK (run_start_minute >= 0 and run_start_minute < (24 * 60));
14
+ ALTER TABLE #{Naf.schema_name}.application_schedules ALTER COLUMN run_interval DROP NOT NULL;
15
+ ALTER TABLE #{Naf.schema_name}.application_schedules ALTER COLUMN run_interval_style_id DROP NOT NULL;
16
+ SQL
17
+ end
18
+ end
data/lib/naf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Naf
2
- VERSION = "2.0.4"
2
+ VERSION = "2.1.0"
3
3
  end
data/naf.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.name = "naf"
9
9
  s.version = Naf::VERSION
10
10
  s.license = 'New BSD License'
11
- s.date = '2014-01-10'
11
+ s.date = '2014-01-24'
12
12
  s.summary = "Creates infrastructure for a customizable and robust Postgres-backed script scheduling/running"
13
13
  s.description = "A cloud based distributed cron, application framework and operations console. Naf works as a distributed script running " +
14
14
  "system that provides scheduling, logging, alarming, machine redundancy, and the ability to set constraint during script execution"
@@ -6,29 +6,29 @@ module Naf
6
6
  let(:model_class) { ApplicationScheduleAffinityTab }
7
7
 
8
8
  it "should respond with index action nested under application schedule" do
9
- model_class.should_receive(:where).with({ application_schedule_id: "1" }).and_return([])
9
+ model_class.should_receive(:where).with({ application_schedule_id: '1' }).and_return([])
10
10
  get :index, application_schedule_id: 1
11
- response.should render_template("naf/datatable")
11
+ response.should render_template('naf/datatable')
12
12
  response.should be_success
13
13
  end
14
14
 
15
15
  it "should respond with the show action" do
16
- model_class.should_receive(:find).with("5").and_return(nil)
16
+ model_class.should_receive(:find).with('5').and_return(nil)
17
17
  schedule = double('schedule')
18
18
  schedule.should_receive(:application).and_return(nil)
19
- ApplicationSchedule.should_receive(:find).with("1").and_return(schedule)
19
+ ApplicationSchedule.should_receive(:find).with('1').and_return(schedule)
20
20
  get :show, id: 5, application_schedule_id: 1
21
- response.should render_template("naf/record")
21
+ response.should render_template('naf/record')
22
22
  response.should be_success
23
23
  end
24
24
 
25
25
  it "should respond with the edit action" do
26
- model_class.should_receive(:find).with("5").and_return(nil)
26
+ model_class.should_receive(:find).with('5').and_return(nil)
27
27
  schedule = double('schedule')
28
28
  schedule.should_receive(:application).and_return(nil)
29
- ApplicationSchedule.should_receive(:find).with("1").and_return(schedule)
29
+ ApplicationSchedule.should_receive(:find).with('1').and_return(schedule)
30
30
  get :edit, id: 5, application_schedule_id: 1
31
- response.should render_template("naf/application_schedule_affinity_tabs/edit")
31
+ response.should render_template('naf/application_schedule_affinity_tabs/edit')
32
32
  response.should be_success
33
33
  end
34
34
 
@@ -36,14 +36,17 @@ module Naf
36
36
  model_class.should_receive(:new).and_return(nil)
37
37
  schedule = double('schedule')
38
38
  schedule.should_receive(:application).and_return(nil)
39
- ApplicationSchedule.should_receive(:find).with("1").and_return(schedule)
39
+ ApplicationSchedule.should_receive(:find).with('1').and_return(schedule)
40
40
  get :new, id: 5, application_schedule_id: 1
41
- response.should render_template("naf/application_schedule_affinity_tabs/new")
41
+ response.should render_template('naf/application_schedule_affinity_tabs/new')
42
42
  response.should be_success
43
43
  end
44
44
 
45
45
  context "on the create action" do
46
- let(:valid_tab) { mock_model(model_class, save: true, id: 5, application_schedule_id: 1, application_id: 1) }
46
+ let(:valid_tab) { mock_model(model_class, save: true,
47
+ id: 5,
48
+ application_schedule_id: 1,
49
+ application_id: 1) }
47
50
  let(:invalid_tab) { mock_model(model_class, save: false) }
48
51
  let(:schedule) { mock_model(ApplicationSchedule, id: 1) }
49
52
  let(:application) { mock_model(Application, id: 1) }
@@ -52,47 +55,51 @@ module Naf
52
55
  post :create, application_schedule_id: 1, application_id: 1
53
56
  end
54
57
 
55
- before(:each) do
56
- Application.should_receive(:find).with("1").and_return(application)
57
- ApplicationSchedule.should_receive(:find).with("1").and_return(schedule)
58
+ before do
59
+ ApplicationSchedule.should_receive(:find).with('1').and_return(schedule)
58
60
  end
59
61
 
60
62
  it "should redirect to show when valid" do
61
63
  model_class.should_receive(:new).and_return(valid_tab)
62
- valid_tab.stub(:affinity_name).and_return("Test Name")
63
- path = application_application_schedule_application_schedule_affinity_tab_path(application, schedule, valid_tab)
64
+ valid_tab.stub(:affinity_name).and_return('Test Name')
65
+ path = application_schedule_application_schedule_affinity_tab_path(schedule, valid_tab)
64
66
  subject.should redirect_to(path)
65
67
  end
66
68
  it "should re-render to new when invalid" do
67
69
  model_class.should_receive(:new).and_return(invalid_tab)
68
- subject.should render_template("naf/application_schedule_affinity_tabs/new")
70
+ subject.should render_template('naf/application_schedule_affinity_tabs/new')
69
71
  end
70
72
  end
71
73
 
72
74
  context "on the update action" do
73
- let(:valid_tab) { mock_model(model_class, update_attributes: true, id: 5, application_schedule_id: 1, application_id: 1) }
74
- let(:invalid_tab) { mock_model(model_class, update_attributes: false, id: 5, application_schedule_id: 1, application_id: 1) }
75
+ let(:valid_tab) { mock_model(model_class, update_attributes: true,
76
+ id: 5,
77
+ application_schedule_id: 1,
78
+ application_id: 1) }
79
+ let(:invalid_tab) { mock_model(model_class, update_attributes: false,
80
+ id: 5,
81
+ application_schedule_id: 1,
82
+ application_id: 1) }
75
83
  let(:schedule) { mock_model(ApplicationSchedule, id: 1) }
76
- let(:application) { mock_model(Application, id: 1) }
77
84
 
78
85
  subject do
79
- put :update, application_schedule_id: 1, application_id: 1, id: 5
86
+ put :update, application_schedule_id: 1, id: 5
80
87
  end
81
88
 
82
- before(:each) do
83
- Application.should_receive(:find).with("1").and_return(application)
84
- ApplicationSchedule.should_receive(:find).with("1").and_return(schedule)
89
+ before do
90
+ ApplicationSchedule.should_receive(:find).with('1').and_return(schedule)
85
91
  end
86
92
 
87
93
  it "should redirect to show when valid" do
88
94
  model_class.should_receive(:find).and_return(valid_tab)
89
- valid_tab.stub(:affinity_name).and_return("Test Name")
90
- path = application_application_schedule_application_schedule_affinity_tab_path(application, schedule, valid_tab)
95
+ valid_tab.stub(:affinity_name).and_return('Test Name')
96
+ path = application_schedule_application_schedule_affinity_tab_path(schedule, valid_tab)
91
97
  subject.should redirect_to(path)
92
98
  end
99
+
93
100
  it "should re-render to edit when invalid" do
94
101
  model_class.should_receive(:find).and_return(invalid_tab)
95
- subject.should render_template("naf/application_schedule_affinity_tabs/edit")
102
+ subject.should render_template('naf/application_schedule_affinity_tabs/edit')
96
103
  end
97
104
  end
98
105