authorized_rails_scaffolds 0.0.14 → 0.0.15

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -0
  3. data/lib/authorized_rails_scaffolds.rb +23 -6
  4. data/lib/authorized_rails_scaffolds/helper.rb +13 -54
  5. data/lib/authorized_rails_scaffolds/{controller_macros.rb → macros/controller_macros.rb} +1 -1
  6. data/lib/authorized_rails_scaffolds/{factory_macros.rb → macros/factory_macros.rb} +5 -5
  7. data/lib/authorized_rails_scaffolds/macros/parent_macros.rb +56 -0
  8. data/lib/authorized_rails_scaffolds/macros/path_macros.rb +70 -0
  9. data/lib/authorized_rails_scaffolds/macros/resource_macros.rb +53 -0
  10. data/lib/authorized_rails_scaffolds/macros/route_example_macros.rb +65 -0
  11. data/lib/authorized_rails_scaffolds/{test_var_macros.rb → macros/test_var_macros.rb} +9 -9
  12. data/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper.rb +0 -25
  13. data/lib/authorized_rails_scaffolds/rails_helper_helper.rb +41 -0
  14. data/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper.rb +27 -2
  15. data/lib/authorized_rails_scaffolds/rspec_integration_helper.rb +9 -0
  16. data/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper.rb +8 -4
  17. data/lib/authorized_rails_scaffolds/rspec_scaffold_helper.rb +5 -4
  18. data/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper.rb +2 -2
  19. data/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper.rb +1 -1
  20. data/lib/authorized_rails_scaffolds/version.rb +1 -1
  21. data/lib/generators/authorized_rails_scaffolds/install_macros/install_macros_generator.rb +2 -1
  22. data/lib/generators/authorized_rails_scaffolds/install_macros/templates/devise_can_can/USAGE +1 -0
  23. data/lib/generators/authorized_rails_scaffolds/install_macros/templates/devise_can_can/request_macros.rb +8 -0
  24. data/lib/generators/authorized_rails_scaffolds/install_templates/install_templates_generator.rb +14 -0
  25. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/_form.html.erb +2 -1
  26. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/controller.rb +68 -35
  27. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/helper.rb +25 -0
  28. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/index.html.erb +15 -15
  29. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/show.html.erb +1 -1
  30. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/controller_spec.rb +90 -84
  31. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/edit_spec.rb +37 -30
  32. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/index_spec.rb +56 -51
  33. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/new_spec.rb +33 -26
  34. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/request_spec.rb +125 -0
  35. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/routing_spec.rb +12 -9
  36. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/show_spec.rb +20 -17
  37. data/spec/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper_spec.rb +24 -23
  38. data/spec/lib/authorized_rails_scaffolds/rails_helper_helper_spec.rb +66 -0
  39. data/spec/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper_spec.rb +42 -0
  40. data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper_spec.rb +7 -7
  41. data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper_spec.rb +14 -14
  42. data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper_spec.rb +4 -4
  43. metadata +16 -7
  44. data/lib/authorized_rails_scaffolds/resource_macros.rb +0 -81
  45. data/lib/authorized_rails_scaffolds/route_example_macros.rb +0 -43
@@ -11,11 +11,11 @@ t_helper = AuthorizedRailsScaffolds::RSpecScaffoldViewHelper.new(
11
11
 
12
12
  resource_symbol = t_helper.resource_symbol
13
13
  resource_test_var = t_helper.resource_test_var
14
- resource_table_name = t_helper.resource_table_name
15
- resource_test_property = t_helper.resource_test_property
14
+ resource_name = t_helper.resource_name
15
+ resource_test_name = t_helper.resource_test_name
16
16
 
17
17
  resource_directory = t_helper.resource_directory
18
- parent_model_tables = t_helper.parent_model_tables
18
+ parent_model_names = t_helper.parent_model_names
19
19
 
20
20
  output_attributes = t_helper.output_attributes
21
21
  datetime_attributes = t_helper.datetime_attributes
@@ -25,54 +25,61 @@ standard_attributes = t_helper.standard_attributes
25
25
  -%>
26
26
  describe "<%= resource_directory %>/edit" do
27
27
 
28
- <% parent_model_tables.each_with_index do |parent_model, index| -%>
28
+ <% parent_model_names.each_with_index do |parent_model, index| -%>
29
29
  <%- if index == 0 -%>
30
30
  let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
31
31
  <%- else -%>
32
- let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>, :<%= parent_model_tables[index - 1] %> => <%= parent_model_tables[index - 1] %>) }
32
+ let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>, :<%= parent_model_names[index - 1] %> => <%= parent_model_names[index - 1] %>) }
33
33
  <%- end -%>
34
34
  <%- end -%>
35
35
  <% references_attributes.each do |parent_attribute| -%>
36
- <%- next if parent_model_tables.include? parent_attribute.name -%>
36
+ <%- next if parent_model_names.include? parent_attribute.name -%>
37
37
  let(<%= t_helper.references_test_sym(parent_attribute.name) %>) { FactoryGirl.build_stubbed(:<%= parent_attribute.name %>) }
38
38
  <% end -%>
39
39
  let(<%= t_helper.resource_test_sym %>) do
40
40
  FactoryGirl.build_stubbed(<%= resource_symbol %><%= output_attributes.empty? ? ')' : ',' %>
41
41
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
42
- :<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.references_test_property(attribute.name) %><% else %><%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><% end %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
42
+ :<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.references_test_name(attribute.name) %><% else %><%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><% end %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
43
43
  <% end -%>
44
44
  <%= output_attributes.empty? ? "" : " )\n" -%>
45
45
  end
46
46
 
47
- context<% if parent_model_tables.any? %> "within <%= parent_model_tables.join('/') %> nesting"<% end %> do<%- unless parent_model_tables.any? -%> # Within default nesting<% end %>
47
+ before(:each) do
48
+ # Stub ability for testing
49
+ @ability = Object.new
50
+ @ability.extend(CanCan::Ability)
51
+ controller.stub(:current_ability) { @ability }
52
+ end
53
+
54
+ context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
48
55
  before(:each) do
49
56
  # Add Properties for view scope
50
- <%- parent_model_tables.each do |parent_model| -%>
51
- assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_property(parent_model) %>)
57
+ <%- parent_model_names.each do |parent_model| -%>
58
+ assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_name(parent_model) %>)
52
59
  <%- end -%>
53
- assign(<%= resource_symbol %>, <%= t_helper.resource_test_property %>)
60
+ assign(<%= resource_symbol %>, <%= t_helper.resource_test_name %>)
54
61
  end
55
62
 
56
- it "renders the edit <%= resource_table_name %> form" do
63
+ it "renders the edit <%= resource_name %> form" do
57
64
  render
58
65
 
59
66
  <% if webrat? -%>
60
- rendered.should have_selector("form", :action => <%= t_helper.controller_show_route resource_test_property %>, :method => "post") do |form|
67
+ rendered.should have_selector("form", :action => <%= t_helper.controller_show_route resource_test_name %>, :method => "post") do |form|
61
68
  <% for attribute in standard_attributes -%>
62
- form.should have_selector("<%= attribute.input_type -%>#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
69
+ form.should have_selector("<%= attribute.input_type -%>#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
63
70
  <% end -%>
64
71
  <% for attribute in references_attributes -%>
65
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>_id", :name => "<%= resource_table_name %>[<%= attribute.name %>_id]")
72
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>_id", :name => "<%= resource_name %>[<%= attribute.name %>_id]")
66
73
  <% end -%>
67
74
  end
68
75
  <% else -%>
69
76
  # Run the generator again with the --webrat flag if you want to use webrat matchers
70
- assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route resource_test_property %>, "post" do
77
+ assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route resource_test_name %>, "post" do
71
78
  <% for attribute in standard_attributes -%>
72
- assert_select "<%= attribute.input_type -%>#<%= resource_table_name %>_<%= attribute.name %>[name=?]", "<%= resource_table_name %>[<%= attribute.name %>]"
79
+ assert_select "<%= attribute.input_type -%>#<%= resource_name %>_<%= attribute.name %>[name=?]", "<%= resource_name %>[<%= attribute.name %>]"
73
80
  <% end -%>
74
81
  <% for attribute in references_attributes -%>
75
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_id[name=?]", "<%= resource_table_name %>[<%= attribute.name %>_id]"
82
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_id[name=?]", "<%= resource_name %>[<%= attribute.name %>_id]"
76
83
  <% end -%>
77
84
  end
78
85
  <% end -%>
@@ -83,40 +90,40 @@ describe "<%= resource_directory %>/edit" do
83
90
  render
84
91
 
85
92
  <% if webrat? -%>
86
- rendered.should have_selector("form", :action => <%= t_helper.controller_show_route resource_test_property %>, :method => "post") do |form|
93
+ rendered.should have_selector("form", :action => <%= t_helper.controller_show_route resource_test_name %>, :method => "post") do |form|
87
94
  <% for attribute in datetime_attributes -%>
88
95
  <%- if [:date, :datetime].include? attribute.type -%>
89
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
90
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
91
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
96
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
97
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
98
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
92
99
  <%- end -%>
93
100
  <%- if [:time, :datetime].include? attribute.type -%>
94
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
95
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
101
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
102
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
96
103
  <%- end -%>
97
104
  <% end -%>
98
105
  end
99
106
  <% else -%>
100
107
  # Run the generator again with the --webrat flag if you want to use webrat matchers
101
- assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route resource_test_property %>, "post" do
108
+ assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route resource_test_name %>, "post" do
102
109
  <% for attribute in datetime_attributes -%>
103
110
  # <%= attribute.name %> values
104
111
  <%- if [:date, :datetime].include? attribute.type -%>
105
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_1i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(1i)]" do
112
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_1i[name=?]", "<%= resource_name %>[<%= attribute.name %>(1i)]" do
106
113
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
107
114
  end
108
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_2i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(2i)]" do
115
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_2i[name=?]", "<%= resource_name %>[<%= attribute.name %>(2i)]" do
109
116
  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
110
117
  end
111
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_3i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(3i)]" do
118
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_3i[name=?]", "<%= resource_name %>[<%= attribute.name %>(3i)]" do
112
119
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
113
120
  end
114
121
  <%- end -%>
115
122
  <%- if [:time, :datetime].include? attribute.type -%>
116
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_4i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(4i)]" do
123
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_4i[name=?]", "<%= resource_name %>[<%= attribute.name %>(4i)]" do
117
124
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
118
125
  end
119
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_5i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(5i)]" do
126
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_5i[name=?]", "<%= resource_name %>[<%= attribute.name %>(5i)]" do
120
127
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
121
128
  end
122
129
  <%- end -%>
@@ -10,11 +10,11 @@ t_helper = AuthorizedRailsScaffolds::RSpecScaffoldViewHelper.new(
10
10
  )
11
11
 
12
12
  resource_directory = t_helper.resource_directory
13
- parent_model_tables = t_helper.parent_model_tables
13
+ parent_model_names = t_helper.parent_model_names
14
14
 
15
15
  resource_class = t_helper.resource_class # Non-Namespaced class name
16
16
  resource_symbol = t_helper.resource_symbol
17
- resource_table_name = t_helper.resource_table_name
17
+ resource_name = t_helper.resource_name
18
18
 
19
19
  output_attributes = t_helper.output_attributes
20
20
  datetime_attributes = t_helper.datetime_attributes
@@ -24,75 +24,80 @@ standard_attributes = t_helper.standard_attributes
24
24
  -%>
25
25
  describe "<%= resource_directory %>/index" do
26
26
 
27
- <% parent_model_tables.each_with_index do |parent_model, index| -%>
27
+ <% parent_model_names.each_with_index do |parent_model, index| -%>
28
28
  <%- if index == 0 -%>
29
29
  let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
30
30
  <%- else -%>
31
- let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>, :<%= parent_model_tables[index - 1] %> => <%= parent_model_tables[index - 1] %>) }
31
+ let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>, :<%= parent_model_names[index - 1] %> => <%= parent_model_names[index - 1] %>) }
32
32
  <%- end -%>
33
33
  <%- end -%>
34
34
  <% references_attributes.each do |parent_attribute| -%>
35
- <%- next if parent_model_tables.include? parent_attribute.name -%>
35
+ <%- next if parent_model_names.include? parent_attribute.name -%>
36
36
  let(<%= t_helper.references_test_sym(parent_attribute.name) %>) { FactoryGirl.build_stubbed(:<%= parent_attribute.name %>) }
37
37
  <% end -%>
38
38
  <% [1,2].each_with_index do |id, model_index| -%>
39
39
  let(<%= t_helper.resource_test_sym(id) %>) do
40
40
  FactoryGirl.build_stubbed(<%= resource_symbol %><%= output_attributes.empty? ? ')' : ',' %>
41
41
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
42
- :<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.references_test_property(attribute.name) %><% else %><%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><% end %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
42
+ :<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.references_test_name(attribute.name) %><% else %><%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><% end %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
43
43
  <% end -%>
44
44
  <%= output_attributes.empty? ? "" : " )\n" -%>
45
45
  end
46
46
  <% end -%>
47
47
 
48
- context<% if parent_model_tables.any? %> "within <%= parent_model_tables.join('/') %> nesting"<% end %> do<%- unless parent_model_tables.any? -%> # Within default nesting<% end %>
48
+ before(:each) do
49
+ # Stub ability for testing
50
+ @ability = Object.new
51
+ @ability.extend(CanCan::Ability)
52
+ controller.stub(:current_ability) { @ability }
53
+ end
54
+
55
+ context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
49
56
  before(:each) do
50
57
  # Add Properties for view scope
51
- <%- parent_model_tables.each do |parent_model| -%>
52
- assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_property(parent_model) %>)
58
+ <%- parent_model_names.each do |parent_model| -%>
59
+ assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_name(parent_model) %>)
53
60
  <%- end -%>
54
- assign(<%= t_helper.resource_plural_sym %>, [
61
+ <%= t_helper.resource_array_name %> = [
55
62
  <% [1,2].each_with_index do |id, model_index| -%>
56
- <%= t_helper.resource_test_property(id) %><%= model_index == 1 ? '' : ',' %>
63
+ <%= t_helper.resource_test_name(id) %><%= model_index == 1 ? '' : ',' %>
57
64
  <% end -%>
58
- ])
59
-
60
- @ability = Object.new
61
- @ability.extend(CanCan::Ability)
62
- controller.stub(:current_ability) { @ability }
65
+ ]
66
+ # <%= t_helper.resource_array_name %> = Kaminari.paginate_array(<%= t_helper.resource_array_name %>).page(1)
67
+ assign(<%= t_helper.resource_array_sym %>, <%= t_helper.resource_array_name %>)
63
68
  end
64
69
 
65
70
  describe "page header" do
66
71
  it 'includes a h1 title' do
67
72
  render
68
73
  <% if webrat? -%>
69
- rendered.should have_selector(".page-header>h1", :content => <%= resource_table_name.humanize.pluralize.dump %>, :count => 1)
74
+ rendered.should have_selector(".page-header>h1", :content => <%= resource_name.humanize.pluralize.dump %>, :count => 1)
70
75
  <% else -%>
71
- assert_select ".page-header>h1", :text => <%= resource_table_name.humanize.pluralize.dump %>, :count => 1
76
+ assert_select ".page-header>h1", :text => <%= resource_name.humanize.pluralize.dump %>, :count => 1
72
77
  <% end -%>
73
78
  end
74
79
  end
75
80
 
76
- describe "<%= t_helper.resource_plural_name %> table" do
77
- it 'includes a row for each <%= resource_table_name %>' do
81
+ describe "<%= t_helper.resource_array_name %> table" do
82
+ it 'includes a row for each <%= resource_name %>' do
78
83
  render
79
84
  <% unless webrat? -%>
80
85
  # Run the generator again with the --webrat flag if you want to use webrat matchers
81
86
  <% end -%>
82
87
  <% [1,2].each do |model_index| -%>
83
88
  <% if webrat? -%>
84
- rendered.should have_selector("table>tbody>tr.<%= resource_table_name %>_#{<%= t_helper.resource_test_property(model_index) %>.id}", :count => 1)
89
+ rendered.should have_selector("table>tbody>tr.<%= resource_name %>_#{<%= t_helper.resource_test_name(model_index) %>.id}", :count => 1)
85
90
  <% else -%>
86
- assert_select "table>tbody>tr.<%= resource_table_name %>_#{<%= t_helper.resource_test_property(model_index) %>.id}", :count => 1
91
+ assert_select "table>tbody>tr.<%= resource_name %>_#{<%= t_helper.resource_test_name(model_index) %>.id}", :count => 1
87
92
  <% end -%>
88
93
  <% end -%>
89
94
  end
90
95
 
91
- it "contains a list of <%= t_helper.resource_plural_name %>" do
96
+ it "contains a list of <%= t_helper.resource_array_name %>" do
92
97
  render
93
98
  <% if webrat? -%>
94
99
  <%- [1,2].each do |model_index| -%>
95
- rendered.should have_selector("tr>td.id-column", :content => <%= t_helper.resource_test_property(model_index) %>.id.to_s, :count => 1)
100
+ rendered.should have_selector("tr>td.id-column", :content => <%= t_helper.resource_test_name(model_index) %>.id.to_s, :count => 1)
96
101
  <%- end -%>
97
102
  <%- standard_attributes.each_with_index do |attribute, attribute_index| -%>
98
103
  rendered.should have_selector("tr>td", :content => <%= factory_attribute_string attribute.type, value_for(attribute) %>.to_s, :count => 2)
@@ -103,7 +108,7 @@ describe "<%= resource_directory %>/index" do
103
108
  <% else -%>
104
109
  # Run the generator again with the --webrat flag if you want to use webrat matchers
105
110
  <%- [1,2].each do |model_index| -%>
106
- assert_select "tr>td.id-column", :text => <%= t_helper.resource_test_property(model_index) %>.id.to_s, :count => 1
111
+ assert_select "tr>td.id-column", :text => <%= t_helper.resource_test_name(model_index) %>.id.to_s, :count => 1
107
112
  <%- end -%>
108
113
  <%- standard_attributes.each_with_index do |attribute, attribute_index| -%>
109
114
  assert_select "tr>td", :text => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s, :count => 2
@@ -114,52 +119,52 @@ describe "<%= resource_directory %>/index" do
114
119
  <% end -%>
115
120
  end
116
121
  <% references_attributes.each_with_index do |attribute, attribute_index| -%>
117
- <%- next if parent_model_tables.include?(attribute.name.to_s) -%>
122
+ <%- next if parent_model_names.include?(attribute.name.to_s) -%>
118
123
 
119
- it "displays the <%= attribute.name %> belonging to <%= resource_table_name %>" do
124
+ it "displays the <%= attribute.name %> belonging to <%= resource_name %>" do
120
125
  render
121
126
  <%- if webrat? -%>
122
- rendered.should have_selector("tr>td", :content => <%= t_helper.references_test_property(attribute.name) %>.to_s, :count => 2)
127
+ rendered.should have_selector("tr>td", :content => <%= t_helper.references_test_name(attribute.name) %>.to_s, :count => 2)
123
128
  <%- else -%>
124
- assert_select "tr>td", :text => <%= t_helper.references_test_property(attribute.name) %>.to_s, :count => 2
129
+ assert_select "tr>td", :text => <%= t_helper.references_test_name(attribute.name) %>.to_s, :count => 2
125
130
  <%- end -%>
126
131
  end
127
132
  <% end -%>
128
133
  <% references_attributes.each_with_index do |attribute, attribute_index| -%>
129
- <%- next unless parent_model_tables.include?(attribute.name.to_s) -%>
134
+ <%- next unless parent_model_names.include?(attribute.name.to_s) -%>
130
135
 
131
- it "does not display the <%= attribute.name %> belonging to <%= resource_table_name %>" do
136
+ it "does not display the <%= attribute.name %> belonging to <%= resource_name %>" do
132
137
  render
133
138
  <%- if webrat? -%>
134
- rendered.should have_selector("tr>td", :content => <%= t_helper.references_test_property(attribute.name) %>.to_s, :count => 0)
139
+ rendered.should have_selector("tr>td", :content => <%= t_helper.references_test_name(attribute.name) %>.to_s, :count => 0)
135
140
  <%- else -%>
136
- assert_select "tr>td", :text => <%= t_helper.references_test_property(attribute.name) %>.to_s, :count => 0
141
+ assert_select "tr>td", :text => <%= t_helper.references_test_name(attribute.name) %>.to_s, :count => 0
137
142
  <%- end -%>
138
143
  end
139
144
  <% end -%>
140
145
 
141
- describe 'show <%= resource_table_name %> link' do
146
+ describe 'show <%= resource_name %> link' do
142
147
  it "renders a link to <%= ns_file_name %>_path" do
143
148
  render
144
149
  <% [1,2].each do |model_index| -%>
145
150
  <%- if webrat? -%>
146
- rendered.should have_selector("td>a[href]:not([data-method])", :href => <%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1)
151
+ rendered.should have_selector("td>a[href]:not([data-method])", :href => <%= t_helper.controller_show_route t_helper.resource_test_name(model_index) %>, :count => 1)
147
152
  <%- else -%>
148
- assert_select "td>a[href=?]:not([data-method])", <%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1
153
+ assert_select "td>a[href=?]:not([data-method])", <%= t_helper.controller_show_route t_helper.resource_test_name(model_index) %>, :count => 1
149
154
  <%- end -%>
150
155
  <% end -%>
151
156
  end
152
157
  end
153
158
 
154
- describe 'edit <%= resource_table_name %> link' do
159
+ describe 'edit <%= resource_name %> link' do
155
160
  context 'without update permissions' do
156
161
  it "renders a disabled link to edit_<%= ns_file_name %>_path" do
157
162
  render
158
163
  <% [1,2].each do |model_index| -%>
159
164
  <%- if webrat? -%>
160
- rendered.should_not have_selector("td>a[href][disabled=disabled]", :href => edit_<%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1)
165
+ rendered.should_not have_selector("td>a[href][disabled=disabled]", :href => <%= t_helper.controller_edit_route t_helper.resource_test_name(model_index) %>, :count => 1)
161
166
  <%- else -%>
162
- assert_select "td>a[href=?][disabled=disabled]", edit_<%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1
167
+ assert_select "td>a[href=?][disabled=disabled]", <%= t_helper.controller_edit_route t_helper.resource_test_name(model_index) %>, :count => 1
163
168
  <%- end -%>
164
169
  <% end -%>
165
170
  end
@@ -170,24 +175,24 @@ describe "<%= resource_directory %>/index" do
170
175
  render
171
176
  <% [1,2].each do |model_index| -%>
172
177
  <%- if webrat? -%>
173
- rendered.should have_selector("td>a[href]:not([disabled])", :href => edit_<%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1)
178
+ rendered.should have_selector("td>a[href]:not([disabled])", :href => <%= t_helper.controller_edit_route t_helper.resource_test_name(model_index) %>, :count => 1)
174
179
  <%- else -%>
175
- assert_select "td>a[href=?]:not([disabled])", edit_<%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1
180
+ assert_select "td>a[href=?]:not([disabled])", <%= t_helper.controller_edit_route t_helper.resource_test_name(model_index) %>, :count => 1
176
181
  <%- end -%>
177
182
  <% end -%>
178
183
  end
179
184
  end
180
185
  end
181
186
 
182
- describe 'destroy <%= resource_table_name %> link' do
187
+ describe 'destroy <%= resource_name %> link' do
183
188
  context 'without destroy permissions' do
184
189
  it "renders a disabled link to <%= ns_file_name %>_path" do
185
190
  render
186
191
  <% [1,2].each do |model_index| -%>
187
192
  <%- if webrat? -%>
188
- rendered.should_not have_selector("td>a[href][data-method=delete][disabled=disabled]", :href => <%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1)
193
+ rendered.should_not have_selector("td>a[href][data-method=delete][disabled=disabled]", :href => <%= t_helper.controller_show_route t_helper.resource_test_name(model_index) %>, :count => 1)
189
194
  <%- else -%>
190
- assert_select "td>a[href=?][data-method=delete][disabled=disabled]", <%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1
195
+ assert_select "td>a[href=?][data-method=delete][disabled=disabled]", <%= t_helper.controller_show_route t_helper.resource_test_name(model_index) %>, :count => 1
191
196
  <%- end -%>
192
197
  <% end -%>
193
198
  end
@@ -198,9 +203,9 @@ describe "<%= resource_directory %>/index" do
198
203
  render
199
204
  <% [1,2].each do |model_index| -%>
200
205
  <%- if webrat? -%>
201
- rendered.should have_selector("td>a[href][data-method=delete]:not([disabled])", :href => <%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1)
206
+ rendered.should have_selector("td>a[href][data-method=delete]:not([disabled])", :href => <%= t_helper.controller_show_route t_helper.resource_test_name(model_index) %>, :count => 1)
202
207
  <%- else -%>
203
- assert_select "td>a[href=?][data-method=delete]:not([disabled])", <%= t_helper.controller_show_route t_helper.resource_test_property(model_index) %>, :count => 1
208
+ assert_select "td>a[href=?][data-method=delete]:not([disabled])", <%= t_helper.controller_show_route t_helper.resource_test_name(model_index) %>, :count => 1
204
209
  <%- end -%>
205
210
  <% end -%>
206
211
  end
@@ -208,14 +213,14 @@ describe "<%= resource_directory %>/index" do
208
213
  end
209
214
  end
210
215
 
211
- describe 'new <%= resource_table_name %> link' do
216
+ describe 'new <%= resource_name %> link' do
212
217
  context 'without create permissions' do
213
218
  it "does not render a link to new_<%= ns_file_name %>_path" do
214
219
  render
215
220
  <% if webrat? -%>
216
- rendered.should_not have_selector("a[href=?]", :href => new_<%= t_helper.controller_show_route %>, :count => 1)
221
+ rendered.should_not have_selector("a[href=?]", :href => <%= t_helper.controller_new_route %>, :count => 1)
217
222
  <% else -%>
218
- assert_select "a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 0
223
+ assert_select "a[href=?]", <%= t_helper.controller_new_route %>, :count => 0
219
224
  <% end -%>
220
225
  end
221
226
  end
@@ -224,9 +229,9 @@ describe "<%= resource_directory %>/index" do
224
229
  @ability.can :create, <%= resource_class %>
225
230
  render
226
231
  <% if webrat? -%>
227
- rendered.should have_selector("a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 1)
232
+ rendered.should have_selector("a[href=?]", <%= t_helper.controller_new_route %>, :count => 1)
228
233
  <% else -%>
229
- assert_select "a[href=?]", new_<%= t_helper.controller_show_route %>, :count => 1
234
+ assert_select "a[href=?]", <%= t_helper.controller_new_route %>, :count => 1
230
235
  <% end -%>
231
236
  end
232
237
  end
@@ -10,10 +10,10 @@ t_helper = AuthorizedRailsScaffolds::RSpecScaffoldViewHelper.new(
10
10
  )
11
11
 
12
12
  resource_symbol = t_helper.resource_symbol
13
- resource_table_name = t_helper.resource_table_name
13
+ resource_name = t_helper.resource_name
14
14
 
15
15
  resource_directory = t_helper.resource_directory
16
- parent_model_tables = t_helper.parent_model_tables
16
+ parent_model_names = t_helper.parent_model_names
17
17
 
18
18
  output_attributes = t_helper.output_attributes
19
19
  datetime_attributes = t_helper.datetime_attributes
@@ -23,54 +23,61 @@ standard_attributes = t_helper.standard_attributes
23
23
  -%>
24
24
  describe "<%= resource_directory %>/new" do
25
25
 
26
- <% parent_model_tables.each_with_index do |parent_model, index| -%>
26
+ <% parent_model_names.each_with_index do |parent_model, index| -%>
27
27
  <%- if index == 0 -%>
28
28
  let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
29
29
  <%- else -%>
30
- let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>, :<%= parent_model_tables[index - 1] %> => <%= parent_model_tables[index - 1] %>) }
30
+ let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>, :<%= parent_model_names[index - 1] %> => <%= parent_model_names[index - 1] %>) }
31
31
  <%- end -%>
32
32
  <%- end -%>
33
33
  <% references_attributes.each do |parent_attribute| -%>
34
- <%- next if parent_model_tables.include? parent_attribute.name -%>
34
+ <%- next if parent_model_names.include? parent_attribute.name -%>
35
35
  let(<%= t_helper.references_test_sym(parent_attribute.name) %>) { FactoryGirl.build_stubbed(:<%= parent_attribute.name %>) }
36
36
  <% end -%>
37
37
  let(<%= t_helper.resource_test_sym %>) do
38
- FactoryGirl.build(:<%= t_helper.resource_table_name %><%= output_attributes.empty? ? ')' : ',' %>
38
+ FactoryGirl.build(:<%= t_helper.resource_name %><%= output_attributes.empty? ? ')' : ',' %>
39
39
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
40
- :<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.references_test_property(attribute.name) %><% else %><%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><% end %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
40
+ :<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.references_test_name(attribute.name) %><% else %><%= t_helper.factory_attribute_value attribute.type, value_for(attribute) %><% end %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
41
41
  <% end -%>
42
42
  <%= output_attributes.empty? ? "" : " )\n" -%>
43
43
  end
44
44
 
45
- context<% if parent_model_tables.any? %> "within <%= parent_model_tables.join('/') %> nesting"<% end %> do<%- unless parent_model_tables.any? -%> # Within default nesting<% end %>
45
+ before(:each) do
46
+ # Stub ability for testing
47
+ @ability = Object.new
48
+ @ability.extend(CanCan::Ability)
49
+ controller.stub(:current_ability) { @ability }
50
+ end
51
+
52
+ context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
46
53
  before(:each) do
47
54
  # Add Properties for view scope
48
- <%- parent_model_tables.each do |parent_model| -%>
49
- assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_property(parent_model) %>)
55
+ <%- parent_model_names.each do |parent_model| -%>
56
+ assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_name(parent_model) %>)
50
57
  <%- end -%>
51
- assign(<%= resource_symbol %>, <%= t_helper.resource_test_property %>)
58
+ assign(<%= resource_symbol %>, <%= t_helper.resource_test_name %>)
52
59
  end
53
60
 
54
- it "renders new <%= resource_table_name %> form" do
61
+ it "renders new <%= resource_name %> form" do
55
62
  render
56
63
 
57
64
  <% if webrat? -%>
58
65
  rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
59
66
  <% for attribute in standard_attributes -%>
60
- form.should have_selector("<%= attribute.input_type -%>#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
67
+ form.should have_selector("<%= attribute.input_type -%>#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
61
68
  <% end -%>
62
69
  <% for attribute in references_attributes -%>
63
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>_id", :name => "<%= resource_table_name %>[<%= attribute.name %>_id]")
70
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>_id", :name => "<%= resource_name %>[<%= attribute.name %>_id]")
64
71
  <% end -%>
65
72
  end
66
73
  <% else -%>
67
74
  # Run the generator again with the --webrat flag if you want to use webrat matchers
68
75
  assert_select "form[action=?][method=?]", <%= t_helper.controller_index_path %>, "post" do
69
76
  <% for attribute in standard_attributes -%>
70
- assert_select "<%= attribute.input_type -%>#<%= resource_table_name %>_<%= attribute.name %>[name=?]", "<%= resource_table_name %>[<%= attribute.name %>]"
77
+ assert_select "<%= attribute.input_type -%>#<%= resource_name %>_<%= attribute.name %>[name=?]", "<%= resource_name %>[<%= attribute.name %>]"
71
78
  <% end -%>
72
79
  <% for attribute in references_attributes -%>
73
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_id[name=?]", "<%= resource_table_name %>[<%= attribute.name %>_id]"
80
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_id[name=?]", "<%= resource_name %>[<%= attribute.name %>_id]"
74
81
  <% end -%>
75
82
  end
76
83
  <% end -%>
@@ -84,13 +91,13 @@ describe "<%= resource_directory %>/new" do
84
91
  rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
85
92
  <%- for attribute in datetime_attributes -%>
86
93
  <%- if [:date, :datetime].include? attribute.type -%>
87
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
88
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
89
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
94
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
95
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
96
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
90
97
  <%- end -%>
91
98
  <%- if [:time, :datetime].include? attribute.type -%>
92
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
93
- form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
99
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
100
+ form.should have_selector("select#<%= resource_name %>_<%= attribute.name %>", :name => "<%= resource_name %>[<%= attribute.name %>]")
94
101
  <%- end -%>
95
102
  <% end -%>
96
103
  end
@@ -100,21 +107,21 @@ describe "<%= resource_directory %>/new" do
100
107
  <%- for attribute in datetime_attributes -%>
101
108
  # <%= attribute.name %> values
102
109
  <%- if [:date, :datetime].include? attribute.type -%>
103
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_1i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(1i)]" do
110
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_1i[name=?]", "<%= resource_name %>[<%= attribute.name %>(1i)]" do
104
111
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
105
112
  end
106
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_2i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(2i)]" do
113
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_2i[name=?]", "<%= resource_name %>[<%= attribute.name %>(2i)]" do
107
114
  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
108
115
  end
109
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_3i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(3i)]" do
116
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_3i[name=?]", "<%= resource_name %>[<%= attribute.name %>(3i)]" do
110
117
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
111
118
  end
112
119
  <%- end -%>
113
120
  <%- if [:time, :datetime].include? attribute.type -%>
114
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_4i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(4i)]" do
121
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_4i[name=?]", "<%= resource_name %>[<%= attribute.name %>(4i)]" do
115
122
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
116
123
  end
117
- assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_5i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(5i)]" do
124
+ assert_select "select#<%= resource_name %>_<%= attribute.name %>_5i[name=?]", "<%= resource_name %>[<%= attribute.name %>(5i)]" do
118
125
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
119
126
  end
120
127
  <%- end -%>