authorized_rails_scaffolds 0.0.10 → 0.0.11

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