authorized_rails_scaffolds 0.0.8 → 0.0.9

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.
@@ -18,10 +18,11 @@ datetime_attributes = t_helper.datetime_attributes
18
18
 
19
19
  -%>
20
20
  describe "<%= ns_table_name %>/edit" do
21
+
21
22
  before(:each) do
22
- <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
23
+ <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
23
24
  @<%= model.underscore %> = assign(:<%= model.underscore %>, FactoryGirl.build_stubbed(:<%= model.underscore %>))
24
- <%- end -%>
25
+ <%- end -%>
25
26
  @<%= var_name %> = assign(:<%= var_name %>, FactoryGirl.build_stubbed(:<%= var_name %><%= output_attributes.empty? ? '))' : ',' %>
26
27
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
27
28
  :<%= attribute.name %> => <%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
@@ -29,79 +30,87 @@ describe "<%= ns_table_name %>/edit" do
29
30
  <%= output_attributes.empty? ? "" : " ))\n" -%>
30
31
  end
31
32
 
32
- it "renders the edit <%= var_name %> form" do
33
- render
33
+ context do # Within default nesting
34
+ before(:each) do
35
+ <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
36
+ assign(:<%= model.underscore %>, @<%= model.underscore %>)
37
+ <%- end -%>
38
+ end
39
+
40
+ it "renders the edit <%= var_name %> form" do
41
+ render
34
42
 
35
43
  <% if webrat? -%>
36
- rendered.should have_selector("form", :action => <%= t_helper.controller_show_route "@#{var_name}" %>, :method => "post") do |form|
44
+ rendered.should have_selector("form", :action => <%= t_helper.controller_show_route "@#{var_name}" %>, :method => "post") do |form|
37
45
  <% for attribute in standard_attributes -%>
38
46
  <%- if attribute.type == :references -%>
39
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>_id", :name => "<%= var_name %>[<%= attribute.name %>_id]")
47
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>_id", :name => "<%= var_name %>[<%= attribute.name %>_id]")
40
48
  <%- else -%>
41
- form.should have_selector("<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
49
+ form.should have_selector("<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
42
50
  <%- end -%>
43
51
  <% end -%>
44
- end
52
+ end
45
53
  <% else -%>
46
- # Run the generator again with the --webrat flag if you want to use webrat matchers
47
- assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route "@#{var_name}" %>, "post" do
54
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
55
+ assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route "@#{var_name}" %>, "post" do
48
56
  <% for attribute in standard_attributes -%>
49
57
  <%- if attribute.type == :references -%>
50
- assert_select "select#<%= var_name %>_<%= attribute.name %>_id[name=?]", "<%= var_name %>[<%= attribute.name %>_id]"
58
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_id[name=?]", "<%= var_name %>[<%= attribute.name %>_id]"
51
59
  <%- else -%>
52
- assert_select "<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>[name=?]", "<%= var_name %>[<%= attribute.name %>]"
60
+ assert_select "<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>[name=?]", "<%= var_name %>[<%= attribute.name %>]"
53
61
  <%- end -%>
54
62
  <% end -%>
55
- end
63
+ end
56
64
  <% end -%>
57
- end
65
+ end
58
66
 
59
67
  <% if datetime_attributes.any? -%>
60
- it "renders all date/time form elements" do
61
- render
68
+ it "renders all date/time form elements" do
69
+ render
62
70
 
63
71
  <% if webrat? -%>
64
- rendered.should have_selector("form", :action => <%= t_helper.controller_show_route "@#{var_name}" %>, :method => "post") do |form|
72
+ rendered.should have_selector("form", :action => <%= t_helper.controller_show_route "@#{var_name}" %>, :method => "post") do |form|
65
73
  <% for attribute in datetime_attributes -%>
66
74
  <%- if [:date, :datetime].include? attribute.type -%>
67
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
68
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
69
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
75
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
76
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
77
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
70
78
  <%- end -%>
71
79
  <%- if [:time, :datetime].include? attribute.type -%>
72
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
73
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
80
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
81
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
74
82
  <%- end -%>
75
83
  <% end -%>
76
- end
84
+ end
77
85
  <% else -%>
78
- # Run the generator again with the --webrat flag if you want to use webrat matchers
79
- assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route "@#{var_name}" %>, "post" do
86
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
87
+ assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route "@#{var_name}" %>, "post" do
80
88
  <% for attribute in datetime_attributes -%>
81
- # <%= attribute.name %> values
89
+ # <%= attribute.name %> values
82
90
  <%- if [:date, :datetime].include? attribute.type -%>
83
- assert_select "select#<%= var_name %>_<%= attribute.name %>_1i[name=?]", "<%= var_name %>[<%= attribute.name %>(1i)]" do
84
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
85
- end
86
- assert_select "select#<%= var_name %>_<%= attribute.name %>_2i[name=?]", "<%= var_name %>[<%= attribute.name %>(2i)]" do
87
- assert_select "option[selected=selected][value=?]", "<%= t_helper.date_select_month_value attribute.default %>", :text => "<%= t_helper.date_select_month_text attribute.default %>", :count => 1
88
- end
89
- assert_select "select#<%= var_name %>_<%= attribute.name %>_3i[name=?]", "<%= var_name %>[<%= attribute.name %>(3i)]" do
90
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
91
- end
91
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_1i[name=?]", "<%= var_name %>[<%= attribute.name %>(1i)]" do
92
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
93
+ end
94
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_2i[name=?]", "<%= var_name %>[<%= attribute.name %>(2i)]" do
95
+ assert_select "option[selected=selected][value=?]", "<%= t_helper.date_select_month_value attribute.default %>", :text => "<%= t_helper.date_select_month_text attribute.default %>", :count => 1
96
+ end
97
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_3i[name=?]", "<%= var_name %>[<%= attribute.name %>(3i)]" do
98
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
99
+ end
92
100
  <%- end -%>
93
101
  <%- if [:time, :datetime].include? attribute.type -%>
94
- assert_select "select#<%= var_name %>_<%= attribute.name %>_4i[name=?]", "<%= var_name %>[<%= attribute.name %>(4i)]" do
95
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
96
- end
97
- assert_select "select#<%= var_name %>_<%= attribute.name %>_5i[name=?]", "<%= var_name %>[<%= attribute.name %>(5i)]" do
98
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
99
- end
102
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_4i[name=?]", "<%= var_name %>[<%= attribute.name %>(4i)]" do
103
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
104
+ end
105
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_5i[name=?]", "<%= var_name %>[<%= attribute.name %>(5i)]" do
106
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
107
+ end
100
108
  <%- end -%>
101
109
  <% end -%>
102
- end
110
+ end
103
111
  <% end -%>
104
- end
112
+ end
105
113
 
106
114
  <% end -%>
115
+ end
107
116
  end
@@ -17,10 +17,11 @@ output_attributes = t_helper.output_attributes
17
17
 
18
18
  -%>
19
19
  describe "<%= ns_table_name %>/index" do
20
+
20
21
  before(:each) do
21
- <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
22
- @<%= model.underscore %> = assign(:<%= model.underscore %>, FactoryGirl.build_stubbed(:<%= model.underscore %>))
23
- <%- end -%>
22
+ <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
23
+ @<%= model.underscore %> = FactoryGirl.build_stubbed(:<%= model.underscore %>)
24
+ <%- end -%>
24
25
  <% [1,2].each_with_index do |id, model_index| -%>
25
26
  @<%= var_name %>_<%= model_index + 1 %> = FactoryGirl.build_stubbed(:<%= var_name %><%= output_attributes.empty? ? ')' : ',' %>
26
27
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
@@ -35,148 +36,153 @@ describe "<%= ns_table_name %>/index" do
35
36
  @<%= var_name %>_<%= id %><%= model_index == 1 ? '' : ',' %>
36
37
  <% end -%>
37
38
  ])
38
- @ability = Object.new
39
- @ability.extend(CanCan::Ability)
40
- controller.stub(:current_ability) { @ability }
41
39
  end
42
40
 
43
- describe "page header" do
44
- it 'includes a h1 title' do
45
- render
46
- <% if webrat? -%>
47
- rendered.should have_selector(".page-header>h1", :content => <%= var_name.humanize.pluralize.dump %>, :count => 1)
48
- <% else -%>
49
- assert_select ".page-header>h1", :text => <%= var_name.humanize.pluralize.dump %>, :count => 1
50
- <% end -%>
41
+ context do # Within default nesting
42
+ before(:each) do
43
+ @ability = Object.new
44
+ @ability.extend(CanCan::Ability)
45
+ controller.stub(:current_ability) { @ability }
51
46
  end
52
- end
53
47
 
54
- describe "<%= plural_var_name %> table" do
55
- it 'includes a row for each <%= var_name %>' do
56
- render
57
- <% unless webrat? -%>
58
- # Run the generator again with the --webrat flag if you want to use webrat matchers
59
- <% end -%>
60
- <% [1,2].each do |model_index| -%>
48
+ describe "page header" do
49
+ it 'includes a h1 title' do
50
+ render
61
51
  <% if webrat? -%>
62
- rendered.should have_selector("table>tbody>tr.<%= var_name %>_#{@<%= var_name %>_<%= model_index %>.id}", :count => 1)
52
+ rendered.should have_selector(".page-header>h1", :content => <%= var_name.humanize.pluralize.dump %>, :count => 1)
63
53
  <% else -%>
64
- assert_select "table>tbody>tr.<%= var_name %>_#{@<%= var_name %>_<%= model_index %>.id}", :count => 1
65
- <% end -%>
54
+ assert_select ".page-header>h1", :text => <%= var_name.humanize.pluralize.dump %>, :count => 1
66
55
  <% end -%>
56
+ end
67
57
  end
68
58
 
69
- it "contains a list of <%= plural_var_name %>" do
70
- render
59
+ describe "<%= plural_var_name %> table" do
60
+ it 'includes a row for each <%= var_name %>' do
61
+ render
71
62
  <% unless webrat? -%>
72
- # Run the generator again with the --webrat flag if you want to use webrat matchers
63
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
73
64
  <% end -%>
74
65
  <% [1,2].each do |model_index| -%>
75
66
  <% if webrat? -%>
76
- rendered.should have_selector("tr>td.id-column", :content => @<%= var_name %>_<%= model_index %>.id.to_s, :count => 1)
67
+ rendered.should have_selector("table>tbody>tr.<%= var_name %>_#{@<%= var_name %>_<%= model_index %>.id}", :count => 1)
77
68
  <% else -%>
78
- assert_select "tr>td.id-column", :text => @<%= var_name %>_<%= model_index %>.id.to_s, :count => 1
69
+ assert_select "table>tbody>tr.<%= var_name %>_#{@<%= var_name %>_<%= model_index %>.id}", :count => 1
79
70
  <% end -%>
80
71
  <% end -%>
81
- <% output_attributes.each_with_index do |attribute, attribute_index| -%>
82
- <% if webrat? -%>
83
- rendered.should have_selector("tr>td", :content => <%= factory_attribute_string attribute.type, value_for(attribute) %>.to_s, :count => 2)
84
- <% else -%>
85
- assert_select "tr>td", :text => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s, :count => 2
86
- <% end -%>
87
- <% end -%>
88
- end
72
+ end
89
73
 
90
- describe 'show <%= var_name %> link' do
91
- it "renders a link to <%= ns_file_name %>_path" do
74
+ it "contains a list of <%= plural_var_name %>" do
92
75
  render
76
+ <% unless webrat? -%>
77
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
78
+ <% end -%>
93
79
  <% [1,2].each do |model_index| -%>
94
- <% if webrat? -%>
95
- rendered.should have_selector("td>a[href]:not([data-method])", :href => <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
96
- <% else -%>
97
- assert_select "td>a[href=?]:not([data-method])", <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
80
+ <%- if webrat? -%>
81
+ rendered.should have_selector("tr>td.id-column", :content => @<%= var_name %>_<%= model_index %>.id.to_s, :count => 1)
82
+ <%- else -%>
83
+ assert_select "tr>td.id-column", :text => @<%= var_name %>_<%= model_index %>.id.to_s, :count => 1
84
+ <%- end -%>
98
85
  <% end -%>
86
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
87
+ <%- if webrat? -%>
88
+ rendered.should have_selector("tr>td", :content => <%= factory_attribute_string attribute.type, value_for(attribute) %>.to_s, :count => 2)
89
+ <%- else -%>
90
+ assert_select "tr>td", :text => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s, :count => 2
91
+ <%- end -%>
99
92
  <% end -%>
100
93
  end
101
- end
102
94
 
103
- describe 'edit <%= var_name %> link' do
104
- context 'without update permissions' do
105
- it "renders a disabled link to edit_<%= ns_file_name %>_path" do
95
+ describe 'show <%= var_name %> link' do
96
+ it "renders a link to <%= ns_file_name %>_path" do
106
97
  render
107
98
  <% [1,2].each do |model_index| -%>
108
- <% if webrat? -%>
109
- rendered.should_not have_selector("td>a[href][disabled=disabled]", :href => edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
110
- <% else -%>
111
- assert_select "td>a[href=?][disabled=disabled]", edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
112
- <% end -%>
99
+ <%- if webrat? -%>
100
+ rendered.should have_selector("td>a[href]:not([data-method])", :href => <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
101
+ <%- else -%>
102
+ assert_select "td>a[href=?]:not([data-method])", <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
103
+ <%- end -%>
113
104
  <% end -%>
114
105
  end
115
106
  end
116
- context 'with update permissions' do
117
- it "renders a link to edit_<%= ns_file_name %>_path" do
118
- @ability.can :update, <%= local_class_name %>
119
- render
107
+
108
+ describe 'edit <%= var_name %> link' do
109
+ context 'without update permissions' do
110
+ it "renders a disabled link to edit_<%= ns_file_name %>_path" do
111
+ render
120
112
  <% [1,2].each do |model_index| -%>
121
- <% if webrat? -%>
122
- rendered.should have_selector("td>a[href]:not([disabled])", :href => edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
123
- <% else -%>
124
- assert_select "td>a[href=?]:not([disabled])", edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
113
+ <%- if webrat? -%>
114
+ rendered.should_not have_selector("td>a[href][disabled=disabled]", :href => edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
115
+ <%- else -%>
116
+ assert_select "td>a[href=?][disabled=disabled]", edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
117
+ <%- end -%>
125
118
  <% end -%>
119
+ end
120
+ end
121
+ context 'with update permissions' do
122
+ it "renders a link to edit_<%= ns_file_name %>_path" do
123
+ @ability.can :update, <%= local_class_name %>
124
+ render
125
+ <% [1,2].each do |model_index| -%>
126
+ <%- if webrat? -%>
127
+ rendered.should have_selector("td>a[href]:not([disabled])", :href => edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
128
+ <%- else -%>
129
+ assert_select "td>a[href=?]:not([disabled])", edit_<%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
130
+ <%- end -%>
126
131
  <% end -%>
132
+ end
127
133
  end
128
134
  end
129
- end
130
135
 
131
- describe 'destroy <%= var_name %> link' do
132
- context 'without destroy permissions' do
133
- it "renders a disabled link to <%= ns_file_name %>_path" do
134
- render
136
+ describe 'destroy <%= var_name %> link' do
137
+ context 'without destroy permissions' do
138
+ it "renders a disabled link to <%= ns_file_name %>_path" do
139
+ render
135
140
  <% [1,2].each do |model_index| -%>
136
- <% if webrat? -%>
137
- rendered.should_not have_selector("td>a[href][data-method=delete][disabled=disabled]", :href => <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
138
- <% else -%>
139
- assert_select "td>a[href=?][data-method=delete][disabled=disabled]", <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
140
- <% end -%>
141
+ <%- if webrat? -%>
142
+ rendered.should_not have_selector("td>a[href][data-method=delete][disabled=disabled]", :href => <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
143
+ <%- else -%>
144
+ assert_select "td>a[href=?][data-method=delete][disabled=disabled]", <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
145
+ <%- end -%>
141
146
  <% end -%>
147
+ end
142
148
  end
143
- end
144
- context 'with destroy permissions' do
145
- it "renders a link to <%= ns_file_name %>_path" do
146
- @ability.can :destroy, <%= local_class_name %>
147
- render
149
+ context 'with destroy permissions' do
150
+ it "renders a link to <%= ns_file_name %>_path" do
151
+ @ability.can :destroy, <%= local_class_name %>
152
+ render
148
153
  <% [1,2].each do |model_index| -%>
149
- <% if webrat? -%>
150
- rendered.should have_selector("td>a[href][data-method=delete]:not([disabled])", :href => <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
151
- <% else -%>
152
- assert_select "td>a[href=?][data-method=delete]:not([disabled])", <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
153
- <% end -%>
154
+ <%- if webrat? -%>
155
+ rendered.should have_selector("td>a[href][data-method=delete]:not([disabled])", :href => <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1)
156
+ <%- else -%>
157
+ assert_select "td>a[href=?][data-method=delete]:not([disabled])", <%= t_helper.controller_show_route "@#{var_name}_#{model_index}" %>, :count => 1
158
+ <%- end -%>
154
159
  <% end -%>
160
+ end
155
161
  end
156
162
  end
157
163
  end
158
- end
159
164
 
160
- describe 'new <%= var_name %> link' do
161
- context 'without create permissions' do
162
- it "does not render a link to new_<%= ns_file_name %>_path" do
163
- render
165
+ describe 'new <%= var_name %> link' do
166
+ context 'without create permissions' do
167
+ it "does not render a link to new_<%= ns_file_name %>_path" do
168
+ render
164
169
  <% if webrat? -%>
165
- rendered.should_not have_selector("a[href=?]", :href => new_<%= t_helper.controller_show_route %>, :count => 1)
170
+ rendered.should_not have_selector("a[href=?]", :href => new_<%= t_helper.controller_show_route %>, :count => 1)
166
171
  <% else -%>
167
- assert_select "a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 0
172
+ assert_select "a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 0
168
173
  <% end -%>
174
+ end
169
175
  end
170
- end
171
- context 'with create permissions' do
172
- it "renders a link to new_<%= ns_file_name %>_path" do
173
- @ability.can :create, <%= local_class_name %>
174
- render
176
+ context 'with create permissions' do
177
+ it "renders a link to new_<%= ns_file_name %>_path" do
178
+ @ability.can :create, <%= local_class_name %>
179
+ render
175
180
  <% if webrat? -%>
176
- rendered.should have_selector("a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 1)
181
+ rendered.should have_selector("a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 1)
177
182
  <% else -%>
178
- assert_select "a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 1
183
+ assert_select "a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 1
179
184
  <% end -%>
185
+ end
180
186
  end
181
187
  end
182
188
  end
@@ -19,87 +19,95 @@ datetime_attributes = t_helper.datetime_attributes
19
19
  -%>
20
20
  describe "<%= ns_table_name %>/new" do
21
21
  before(:each) do
22
- <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
23
- @<%= model.underscore %> = assign(:<%= model.underscore %>, FactoryGirl.build_stubbed(:<%= model.underscore %>))
24
- <%- end -%>
22
+ <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
23
+ @<%= model.underscore %> = FactoryGirl.build_stubbed(:<%= model.underscore %>)
24
+ <%- end -%>
25
25
  assign(:<%= var_name %>, FactoryGirl.build(:<%= var_name %><%= output_attributes.empty? ? '))' : ',' %>
26
26
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
27
27
  :<%= attribute.name %> => <%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
28
28
  <% end -%>
29
29
  <%= !output_attributes.empty? ? " ))\n end" : " end" %>
30
30
 
31
- it "renders new <%= var_name %> form" do
32
- render
31
+ context do # Within default nesting
32
+ before(:each) do
33
+ <%- AuthorizedRailsScaffolds.parent_models.each do |model| -%>
34
+ assign(:<%= model.underscore %>, @<%= model.underscore %>)
35
+ <%- end -%>
36
+ end
37
+
38
+ it "renders new <%= var_name %> form" do
39
+ render
33
40
 
34
41
  <% if webrat? -%>
35
- rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
42
+ rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
36
43
  <% for attribute in standard_attributes -%>
37
44
  <%- if attribute.type == :references -%>
38
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>_id", :name => "<%= var_name %>[<%= attribute.name %>_id]")
45
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>_id", :name => "<%= var_name %>[<%= attribute.name %>_id]")
39
46
  <%- else -%>
40
- form.should have_selector("<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
47
+ form.should have_selector("<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
41
48
  <%- end -%>
42
49
  <% end -%>
43
- end
50
+ end
44
51
  <% else -%>
45
- # Run the generator again with the --webrat flag if you want to use webrat matchers
46
- assert_select "form[action=?][method=?]", <%= t_helper.controller_index_path %>, "post" do
52
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
53
+ assert_select "form[action=?][method=?]", <%= t_helper.controller_index_path %>, "post" do
47
54
  <% for attribute in standard_attributes -%>
48
55
  <%- if attribute.type == :references -%>
49
- assert_select "select#<%= var_name %>_<%= attribute.name %>_id[name=?]", "<%= var_name %>[<%= attribute.name %>_id]"
56
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_id[name=?]", "<%= var_name %>[<%= attribute.name %>_id]"
50
57
  <%- else -%>
51
- assert_select "<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>[name=?]", "<%= var_name %>[<%= attribute.name %>]"
58
+ assert_select "<%= attribute.input_type -%>#<%= var_name %>_<%= attribute.name %>[name=?]", "<%= var_name %>[<%= attribute.name %>]"
52
59
  <%- end -%>
53
60
  <% end -%>
54
- end
61
+ end
55
62
  <% end -%>
56
- end
63
+ end
57
64
 
58
65
  <% if datetime_attributes.any? -%>
59
- it "renders all date/time form elements" do
60
- render
66
+ it "renders all date/time form elements" do
67
+ render
61
68
 
62
69
  <% if webrat? -%>
63
- rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
70
+ rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
64
71
  <% for attribute in datetime_attributes -%>
65
72
  <%- if [:date, :datetime].include? attribute.type -%>
66
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
67
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
68
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
73
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
74
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
75
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
69
76
  <%- end -%>
70
77
  <%- if [:time, :datetime].include? attribute.type -%>
71
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
72
- form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
78
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
79
+ form.should have_selector("select#<%= var_name %>_<%= attribute.name %>", :name => "<%= var_name %>[<%= attribute.name %>]")
73
80
  <%- end -%>
74
81
  <% end -%>
75
- end
82
+ end
76
83
  <% else -%>
77
- # Run the generator again with the --webrat flag if you want to use webrat matchers
78
- assert_select "form[action=?][method=?]", <%= t_helper.controller_index_path %>, "post" do
84
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
85
+ assert_select "form[action=?][method=?]", <%= t_helper.controller_index_path %>, "post" do
79
86
  <% for attribute in datetime_attributes -%>
80
- # <%= attribute.name %> values
87
+ # <%= attribute.name %> values
81
88
  <%- if [:date, :datetime].include? attribute.type -%>
82
- assert_select "select#<%= var_name %>_<%= attribute.name %>_1i[name=?]", "<%= var_name %>[<%= attribute.name %>(1i)]" do
83
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
84
- end
85
- assert_select "select#<%= var_name %>_<%= attribute.name %>_2i[name=?]", "<%= var_name %>[<%= attribute.name %>(2i)]" do
86
- assert_select "option[selected=selected][value=?]", "<%= t_helper.date_select_month_value attribute.default %>", :text => "<%= t_helper.date_select_month_text attribute.default %>", :count => 1
87
- end
88
- assert_select "select#<%= var_name %>_<%= attribute.name %>_3i[name=?]", "<%= var_name %>[<%= attribute.name %>(3i)]" do
89
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
90
- end
89
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_1i[name=?]", "<%= var_name %>[<%= attribute.name %>(1i)]" do
90
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
91
+ end
92
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_2i[name=?]", "<%= var_name %>[<%= attribute.name %>(2i)]" do
93
+ assert_select "option[selected=selected][value=?]", "<%= t_helper.date_select_month_value attribute.default %>", :text => "<%= t_helper.date_select_month_text attribute.default %>", :count => 1
94
+ end
95
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_3i[name=?]", "<%= var_name %>[<%= attribute.name %>(3i)]" do
96
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
97
+ end
91
98
  <%- end -%>
92
99
  <%- if [:time, :datetime].include? attribute.type -%>
93
- assert_select "select#<%= var_name %>_<%= attribute.name %>_4i[name=?]", "<%= var_name %>[<%= attribute.name %>(4i)]" do
94
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
95
- end
96
- assert_select "select#<%= var_name %>_<%= attribute.name %>_5i[name=?]", "<%= var_name %>[<%= attribute.name %>(5i)]" do
97
- assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
98
- end
100
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_4i[name=?]", "<%= var_name %>[<%= attribute.name %>(4i)]" do
101
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
102
+ end
103
+ assert_select "select#<%= var_name %>_<%= attribute.name %>_5i[name=?]", "<%= var_name %>[<%= attribute.name %>(5i)]" do
104
+ assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
105
+ end
99
106
  <%- end -%>
100
107
  <% end -%>
101
- end
108
+ end
102
109
  <% end -%>
110
+ end
103
111
  end
104
112
 
105
113
  <% end -%>