authorized_rails_scaffolds 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
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,75 @@ 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_table_name = t_helper.resource_table_name
14
14
 
15
- controller_directory = t_helper.controller_directory
15
+ resource_directory = t_helper.resource_directory
16
16
  parent_model_tables = t_helper.parent_model_tables
17
17
 
18
18
  output_attributes = t_helper.output_attributes
19
- standard_attributes = t_helper.standard_attributes
20
19
  datetime_attributes = t_helper.datetime_attributes
20
+ references_attributes = t_helper.references_attributes
21
+ standard_attributes = t_helper.standard_attributes
21
22
 
22
23
  -%>
23
- describe "<%= controller_directory %>/new" do
24
+ describe "<%= resource_directory %>/new" do
24
25
 
25
26
  <% parent_model_tables.each_with_index do |parent_model, index| -%>
26
27
  <%- if index == 0 -%>
27
- let(:<%= parent_model %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
28
+ let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
28
29
  <%- else -%>
29
- let(:<%= 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_tables[index - 1] %> => <%= parent_model_tables[index - 1] %>) }
30
31
  <%- end -%>
31
32
  <%- end -%>
32
- let(:<%= var_name %>) do
33
- FactoryGirl.build(:<%= var_name %><%= output_attributes.empty? ? ')' : ',' %>
33
+ <% references_attributes.each do |parent_attribute| -%>
34
+ <%- next if parent_model_tables.include? parent_attribute.name -%>
35
+ let(<%= t_helper.references_test_sym(parent_attribute.name) %>) { FactoryGirl.build_stubbed(:<%= parent_attribute.name %>) }
36
+ <% end -%>
37
+ let(<%= t_helper.resource_test_sym %>) do
38
+ FactoryGirl.build(:<%= t_helper.resource_table_name %><%= output_attributes.empty? ? ')' : ',' %>
34
39
  <% 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 ? '' : ','%>
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 ? '' : ','%>
36
41
  <% end -%>
37
42
  <%= output_attributes.empty? ? "" : " )\n" -%>
38
43
  end
39
44
 
40
- context <% if parent_model_tables.any? %>"within <%= parent_model_tables.join('/') %> nesting"<% end %> do<%- unless parent_model_tables.any? -%> # Within default nesting<% end %>
45
+ context<% if parent_model_tables.any? %> "within <%= parent_model_tables.join('/') %> nesting"<% end %> do<%- unless parent_model_tables.any? -%> # Within default nesting<% end %>
41
46
  before(:each) do
42
47
  # Add Properties for view scope
43
48
  <%- parent_model_tables.each do |parent_model| -%>
44
- assign(:<%= parent_model %>, @<%= parent_model %> = <%= parent_model %>)
49
+ assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_property(parent_model) %>)
45
50
  <%- end -%>
46
- assign(:<%= var_name %>, @<%= var_name %> = <%= var_name %>)
51
+ assign(<%= resource_symbol %>, <%= t_helper.resource_test_property %>)
47
52
  end
48
53
 
49
- it "renders new <%= var_name %> form" do
54
+ it "renders new <%= resource_table_name %> form" do
50
55
  render
51
56
 
52
57
  <% if webrat? -%>
53
58
  rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
54
59
  <% 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 -%>
60
+ form.should have_selector("<%= attribute.input_type -%>#<%= resource_table_name %>_<%= attribute.name %>", :name => "<%= resource_table_name %>[<%= attribute.name %>]")
61
+ <% end -%>
62
+ <% for attribute in references_attributes -%>
63
+ form.should have_selector("select#<%= resource_table_name %>_<%= attribute.name %>_id", :name => "<%= resource_table_name %>[<%= attribute.name %>_id]")
60
64
  <% end -%>
61
65
  end
62
66
  <% else -%>
63
67
  # Run the generator again with the --webrat flag if you want to use webrat matchers
64
68
  assert_select "form[action=?][method=?]", <%= t_helper.controller_index_path %>, "post" do
65
69
  <% 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 -%>
70
+ assert_select "<%= attribute.input_type -%>#<%= resource_table_name %>_<%= attribute.name %>[name=?]", "<%= resource_table_name %>[<%= attribute.name %>]"
71
+ <% end -%>
72
+ <% for attribute in references_attributes -%>
73
+ assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_id[name=?]", "<%= resource_table_name %>[<%= attribute.name %>_id]"
71
74
  <% end -%>
72
75
  end
73
76
  <% end -%>
@@ -81,13 +84,13 @@ describe "<%= controller_directory %>/new" do
81
84
  rendered.should have_selector("form", :action => <%= t_helper.controller_index_path %>, :method => "post") do |form|
82
85
  <%- for attribute in datetime_attributes -%>
83
86
  <%- 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 %>]")
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 %>]")
87
90
  <%- end -%>
88
91
  <%- 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 %>]")
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 %>]")
91
94
  <%- end -%>
92
95
  <% end -%>
93
96
  end
@@ -97,21 +100,21 @@ describe "<%= controller_directory %>/new" do
97
100
  <%- for attribute in datetime_attributes -%>
98
101
  # <%= attribute.name %> values
99
102
  <%- if [:date, :datetime].include? attribute.type -%>
100
- assert_select "select#<%= var_name %>_<%= attribute.name %>_1i[name=?]", "<%= var_name %>[<%= attribute.name %>(1i)]" do
103
+ assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_1i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(1i)]" do
101
104
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_year_value attribute.default %>", :count => 1
102
105
  end
103
- assert_select "select#<%= var_name %>_<%= attribute.name %>_2i[name=?]", "<%= var_name %>[<%= attribute.name %>(2i)]" do
106
+ assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_2i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(2i)]" do
104
107
  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
108
  end
106
- assert_select "select#<%= var_name %>_<%= attribute.name %>_3i[name=?]", "<%= var_name %>[<%= attribute.name %>(3i)]" do
109
+ assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_3i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(3i)]" do
107
110
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_day_value attribute.default %>", :count => 1
108
111
  end
109
112
  <%- end -%>
110
113
  <%- if [:time, :datetime].include? attribute.type -%>
111
- assert_select "select#<%= var_name %>_<%= attribute.name %>_4i[name=?]", "<%= var_name %>[<%= attribute.name %>(4i)]" do
114
+ assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_4i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(4i)]" do
112
115
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_hour_value attribute.default %>", :count => 1
113
116
  end
114
- assert_select "select#<%= var_name %>_<%= attribute.name %>_5i[name=?]", "<%= var_name %>[<%= attribute.name %>(5i)]" do
117
+ assert_select "select#<%= resource_table_name %>_<%= attribute.name %>_5i[name=?]", "<%= resource_table_name %>[<%= attribute.name %>(5i)]" do
115
118
  assert_select "option[selected=selected]", :text => "<%= t_helper.date_select_minute_value attribute.default %>", :count => 1
116
119
  end
117
120
  <%- end -%>
@@ -3,50 +3,61 @@ require "spec_helper"
3
3
  <% module_namespacing do -%>
4
4
  <%-
5
5
 
6
- t_helper = AuthorizedRailsScaffolds::RSpecScaffoldGeneratorHelper.new(
6
+ #
7
+ # Available properties:
8
+ #
9
+ # class_name
10
+ # controller_class_name
11
+ # singular_table_name
12
+ # file_name
13
+ # attributes
14
+ #
15
+
16
+ t_helper = AuthorizedRailsScaffolds::RSpecScaffoldRoutingHelper.new(
7
17
  :class_name => class_name,
18
+ :controller_class_name => controller_class_name,
8
19
  :singular_table_name => singular_table_name,
9
20
  :file_name => file_name,
10
21
  :attributes => attributes
11
22
  )
12
23
 
13
24
  # request_path = t_helper.request_path
14
- controller_directory = t_helper.controller_directory
25
+ resource_directory = t_helper.resource_directory
15
26
  example_controller_path = t_helper.example_controller_path
16
27
  example_controller_path_extra_params = t_helper.example_controller_path_extra_params
17
28
 
18
29
  -%>
19
- describe <%= controller_class_name %>Controller do
30
+ describe <%= t_helper.controller_class_name %> do
20
31
  describe "routing" do
21
32
 
22
33
  <% unless options[:singleton] -%>
23
34
  it "routes to #index" do
24
- get("<%= example_controller_path %>").should route_to("<%= controller_directory %>#index"<%= example_controller_path_extra_params %>)
35
+ get("<%= example_controller_path %>").should route_to("<%= resource_directory %>#index"<%= example_controller_path_extra_params %>)
25
36
  end
26
37
 
27
38
  <% end -%>
28
39
  it "routes to #new" do
29
- get("<%= example_controller_path %>/new").should route_to("<%= controller_directory %>#new"<%= example_controller_path_extra_params %>)
40
+ get("<%= example_controller_path %>/new").should route_to("<%= resource_directory %>#new"<%= example_controller_path_extra_params %>)
30
41
  end
31
42
 
32
43
  it "routes to #show" do
33
- get("<%= example_controller_path %>/1").should route_to("<%= controller_directory %>#show"<%= example_controller_path_extra_params %>, :id => "1")
44
+ get("<%= example_controller_path %>/1").should route_to("<%= resource_directory %>#show"<%= example_controller_path_extra_params %>, :id => "1")
34
45
  end
35
46
 
36
47
  it "routes to #edit" do
37
- get("<%= example_controller_path %>/1/edit").should route_to("<%= controller_directory %>#edit"<%= example_controller_path_extra_params %>, :id => "1")
48
+ get("<%= example_controller_path %>/1/edit").should route_to("<%= resource_directory %>#edit"<%= example_controller_path_extra_params %>, :id => "1")
38
49
  end
39
50
 
40
51
  it "routes to #create" do
41
- post("<%= example_controller_path %>").should route_to("<%= controller_directory %>#create"<%= example_controller_path_extra_params %>)
52
+ post("<%= example_controller_path %>").should route_to("<%= resource_directory %>#create"<%= example_controller_path_extra_params %>)
42
53
  end
43
54
 
44
55
  it "routes to #update" do
45
- put("<%= example_controller_path %>/1").should route_to("<%= controller_directory %>#update"<%= example_controller_path_extra_params %>, :id => "1")
56
+ put("<%= example_controller_path %>/1").should route_to("<%= resource_directory %>#update"<%= example_controller_path_extra_params %>, :id => "1")
46
57
  end
47
58
 
48
59
  it "routes to #destroy" do
49
- delete("<%= example_controller_path %>/1").should route_to("<%= controller_directory %>#destroy"<%= example_controller_path_extra_params %>, :id => "1")
60
+ delete("<%= example_controller_path %>/1").should route_to("<%= resource_directory %>#destroy"<%= example_controller_path_extra_params %>, :id => "1")
50
61
  end
51
62
 
52
63
  end
@@ -2,47 +2,55 @@ 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_var = t_helper.resource_var
13
+ resource_symbol = t_helper.resource_symbol
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
21
+ datetime_attributes = t_helper.datetime_attributes
19
22
  references_attributes = t_helper.references_attributes
23
+ standard_attributes = t_helper.standard_attributes
20
24
 
21
25
  -%>
22
- describe "<%= controller_directory %>/show" do
26
+ describe "<%= resource_directory %>/show" do
23
27
 
24
28
  <% parent_model_tables.each_with_index do |parent_model, index| -%>
25
29
  <%- if index == 0 -%>
26
- let(:<%= parent_model %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
30
+ let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
27
31
  <%- else -%>
28
- 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] %>) }
29
33
  <%- end -%>
30
34
  <%- end -%>
31
- let(:<%= var_name %>) do
32
- 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(:<%= t_helper.resource_table_name %><%= output_attributes.empty? ? ')' : ',' %>
33
41
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
34
- :<%= 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 ? '' : ','%>
35
43
  <% end -%>
36
44
  <%= output_attributes.empty? ? "" : " )\n" -%>
37
45
  end
38
46
 
39
- 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 %>
40
48
  before(:each) do
41
49
  # Add Properties for view scope
42
50
  <%- parent_model_tables.each do |parent_model| -%>
43
- assign(:<%= parent_model %>, @<%= parent_model %> = <%= parent_model %>)
51
+ assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_property(parent_model) %>)
44
52
  <%- end -%>
45
- assign(:<%= var_name %>, @<%= var_name %> = <%= var_name %>)
53
+ assign(<%= resource_symbol %>, <%= t_helper.resource_test_property %>)
46
54
 
47
55
  @ability = Object.new
48
56
  @ability.extend(CanCan::Ability)
@@ -54,7 +62,7 @@ describe "<%= controller_directory %>/show" do
54
62
  <% unless webrat? -%>
55
63
  # Run the generator again with the --webrat flag if you want to use webrat matchers
56
64
  <% end -%>
57
- <% for attribute in output_attributes -%>
65
+ <%- for attribute in standard_attributes -%>
58
66
  <%- if webrat? -%>
59
67
  rendered.should have_selector("dl>dt", :content => <%= "#{attribute.human_name}:".dump %>)
60
68
  rendered.should have_selector("dl>dd", :content => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s)
@@ -62,23 +70,32 @@ describe "<%= controller_directory %>/show" do
62
70
  assert_select "dl>dt", :text => <%= "#{attribute.human_name}:".dump %>
63
71
  assert_select "dl>dd", :text => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s
64
72
  <%- end -%>
65
- <% end -%>
73
+ <%- end -%>
74
+ <%- for attribute in datetime_attributes -%>
75
+ <%- if webrat? -%>
76
+ rendered.should have_selector("dl>dt", :content => <%= "#{attribute.human_name}:".dump %>)
77
+ rendered.should have_selector("dl>dd", :content => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s)
78
+ <%- else -%>
79
+ assert_select "dl>dt", :text => <%= "#{attribute.human_name}:".dump %>
80
+ assert_select "dl>dd", :text => <%= t_helper.factory_attribute_string attribute.type, value_for(attribute) %>.to_s
81
+ <%- end -%>
82
+ <%- end -%>
66
83
  end
67
84
  <% for attribute in references_attributes -%>
68
85
 
69
86
  context "with a <%= attribute.name %> reference" do
70
87
  before(:each) do
71
- @<%= var_name %>.<%= attribute.name %> = FactoryGirl.build_stubbed(:<%= attribute.name %>)
88
+ <%= resource_test_property %>.<%= attribute.name %> = FactoryGirl.build_stubbed(:<%= attribute.name %>)
72
89
  end
73
90
  context 'without read <%= attribute.name.classify %> permissions' do
74
91
  it "should not a render link to <%= attribute.name %>" do
75
92
  render
76
93
  <% if webrat? -%>
77
94
  rendered.should have_selector("dl>dt", :content => <%= "#{attribute.human_name}:".dump %>, :count => 0)
78
- rendered.should have_selector("dl>dd>a[href]", :href => <%= t_helper.references_show_route attribute.name %>, :count => 0)
95
+ rendered.should have_selector("dl>dd>a[href]", :href => <%= t_helper.references_show_route(attribute.name) %>, :count => 0)
79
96
  <% else -%>
80
97
  assert_select "dl>dt", :text => <%= "#{attribute.human_name}:".dump %>, :count => 0
81
- assert_select "dl>dd>a[href=?]", <%= t_helper.references_show_route attribute.name %>, :count => 0
98
+ assert_select "dl>dd>a[href=?]", <%= t_helper.references_show_route(attribute.name) %>, :count => 0
82
99
  <% end -%>
83
100
  end
84
101
  end
@@ -90,10 +107,10 @@ describe "<%= controller_directory %>/show" do
90
107
  render
91
108
  <% if webrat? -%>
92
109
  rendered.should have_selector("dl>dt", :content => <%= "#{attribute.human_name}:".dump %>)
93
- rendered.should have_selector("dl>dd>a[href]", :href => <%= t_helper.references_show_route attribute.name %>, :count => 1)
110
+ rendered.should have_selector("dl>dd>a[href]", :href => <%= t_helper.references_show_route(attribute.name) %>, :count => 1)
94
111
  <% else -%>
95
112
  assert_select "dl>dt", :text => <%= "#{attribute.human_name}:".dump %>
96
- assert_select "dl>dd>a[href=?]", <%= t_helper.references_show_route attribute.name %>, :count => 1
113
+ assert_select "dl>dd>a[href=?]", <%= t_helper.references_show_route(attribute.name) %>, :count => 1
97
114
  <% end -%>
98
115
  end
99
116
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe AuthorizedRailsScaffolds::RailsErbScaffoldHelper do
4
+ include RailsErbScaffoldHelperMacros
5
+
6
+ describe '#scoped_values_for_form' do
7
+ context 'with no parent modules' do
8
+ it 'returns the resource variable' do
9
+ subject = build_rails_erb_scaffold_spec_helper :class_name => 'FooBar', :var_name => 'foo_bar'
10
+ subject.scoped_values_for_form.should eq('@foo_bar')
11
+ end
12
+ end
13
+ context 'with a parent modules' do
14
+ it 'returns a array with the parent module symbol and the resource variable' do
15
+ subject = build_rails_erb_scaffold_spec_helper :class_name => 'Example::FooBar', :var_name => 'foo_bar'
16
+ subject.scoped_values_for_form.should eq('[:example, @foo_bar]')
17
+ end
18
+ end
19
+ context 'with multiple parent modules' do
20
+ it 'returns a array with all parent modules as symbols and the resource variable' do
21
+ subject = build_rails_erb_scaffold_spec_helper :class_name => 'Example::V1::FooBar', :var_name => 'foo_bar'
22
+ subject.scoped_values_for_form.should eq('[:example, :v1, @foo_bar]')
23
+ end
24
+ end
25
+ context 'with a parent model' do
26
+ before(:each) do
27
+ AuthorizedRailsScaffolds.configure do |config|
28
+ config.parent_models = ['Parent']
29
+ end
30
+ end
31
+ context 'with no parent modules' do
32
+ it 'returns a array with the parent model and the resource variable' do
33
+ subject = build_rails_erb_scaffold_spec_helper :class_name => 'FooBar', :var_name => 'foo_bar'
34
+ subject.scoped_values_for_form.should eq('[@parent, @foo_bar]')
35
+ end
36
+ end
37
+ context 'with a parent modules' do
38
+ it 'returns a array with the parent modules, the parent model and the resource variable' do
39
+ subject = build_rails_erb_scaffold_spec_helper :class_name => 'Example::FooBar', :var_name => 'foo_bar'
40
+ subject.scoped_values_for_form.should eq('[:example, @parent, @foo_bar]')
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#resource_var' do
47
+ it 'returns var_name preceeded by an @' do
48
+ subject = build_rails_erb_scaffold_spec_helper :var_name => 'foo_bar'
49
+ subject.resource_var.should eq('@foo_bar')
50
+ end
51
+ context 'with a parent module' do
52
+ it 'falls back to using class_name if var_name is not present' do
53
+ subject = build_rails_erb_scaffold_spec_helper :var_name => nil, :class_name => 'Example::FooBar'
54
+ subject.resource_var.should eq('@foo_bar')
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe AuthorizedRailsScaffolds::RailsScaffoldControllerHelper do
4
+ include RailsScaffoldControllerHelperMacros
5
+
6
+ describe '#application_controller_class' do
7
+ context 'with no parent modules' do
8
+ it 'returns a default ApplicationController' do
9
+ subject = build_rails_controller_spec_helper :class_name => 'FooBar'
10
+ subject.application_controller_class.should eq('ApplicationController')
11
+ end
12
+ end
13
+ context 'with a parent modules' do
14
+ it 'returns a ApplicationController nested within the parent module' do
15
+ subject = build_rails_controller_spec_helper :class_name => 'Example::FooBar'
16
+ subject.application_controller_class.should eq('Example::ApplicationController')
17
+ end
18
+ end
19
+ context 'with multiple parent modules' do
20
+ it 'returns a ApplicationController nested within the parent modules' do
21
+ subject = build_rails_controller_spec_helper :class_name => 'Example::V1::FooBar'
22
+ subject.application_controller_class.should eq('Example::V1::ApplicationController')
23
+ end
24
+ end
25
+ context 'with a parent module' do
26
+ before(:each) do
27
+ AuthorizedRailsScaffolds.configure do |config|
28
+ config.parent_models = ['Parent']
29
+ end
30
+ end
31
+ it 'ignores the parent module value' do
32
+ subject = build_rails_controller_spec_helper :class_name => 'FooBar'
33
+ subject.application_controller_class.should eq('ApplicationController')
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#controller_class_name' do
39
+ context 'with no parent modules' do
40
+ it 'returns the pluralized class_name with Controller appended' do
41
+ subject = build_rails_controller_spec_helper :class_name => 'FooBar'
42
+ subject.controller_class_name.should eq('FooBarsController')
43
+ end
44
+ end
45
+ context 'with a parent modules' do
46
+ it 'returns the pluralized controller class name nested within the parent module' do
47
+ subject = build_rails_controller_spec_helper :class_name => 'Example::FooBar'
48
+ subject.controller_class_name.should eq('Example::FooBarsController')
49
+ end
50
+ end
51
+ context 'with multiple parent modules' do
52
+ it 'returns the pluralized controller class name nested within the parent modules' do
53
+ subject = build_rails_controller_spec_helper :class_name => 'Example::V1::FooBar'
54
+ subject.controller_class_name.should eq('Example::V1::FooBarsController')
55
+ end
56
+ end
57
+ context 'with generated controller_class_name value' do
58
+ it 'returns the generated controller_class_name with Controller appended' do
59
+ subject = build_rails_controller_spec_helper :controller_class_name => 'Example::V1::FooBars'
60
+ subject.controller_class_name.should eq('Example::V1::FooBarsController')
61
+ end
62
+ end
63
+ context 'with a parent module' do
64
+ before(:each) do
65
+ AuthorizedRailsScaffolds.configure do |config|
66
+ config.parent_models = ['Parent']
67
+ end
68
+ end
69
+ it 'ignores the parent module value' do
70
+ subject = build_rails_controller_spec_helper :class_name => 'FooBar'
71
+ subject.controller_class_name.should eq('FooBarsController')
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '#resource_var' do
77
+ it 'returns var_name preceeded by an @' do
78
+ subject = build_rails_controller_spec_helper :var_name => 'foo_bar'
79
+ subject.resource_var.should eq('@foo_bar')
80
+ end
81
+ context 'with a parent module' do
82
+ it 'falls back to using class_name if var_name is not present' do
83
+ subject = build_rails_controller_spec_helper :var_name => nil, :class_name => 'Example::FooBar'
84
+ subject.resource_var.should eq('@foo_bar')
85
+ end
86
+ end
87
+ end
88
+
89
+ end