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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/authorized_rails_scaffolds.rb +23 -6
- data/lib/authorized_rails_scaffolds/helper.rb +13 -54
- data/lib/authorized_rails_scaffolds/{controller_macros.rb → macros/controller_macros.rb} +1 -1
- data/lib/authorized_rails_scaffolds/{factory_macros.rb → macros/factory_macros.rb} +5 -5
- data/lib/authorized_rails_scaffolds/macros/parent_macros.rb +56 -0
- data/lib/authorized_rails_scaffolds/macros/path_macros.rb +70 -0
- data/lib/authorized_rails_scaffolds/macros/resource_macros.rb +53 -0
- data/lib/authorized_rails_scaffolds/macros/route_example_macros.rb +65 -0
- data/lib/authorized_rails_scaffolds/{test_var_macros.rb → macros/test_var_macros.rb} +9 -9
- data/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper.rb +0 -25
- data/lib/authorized_rails_scaffolds/rails_helper_helper.rb +41 -0
- data/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper.rb +27 -2
- data/lib/authorized_rails_scaffolds/rspec_integration_helper.rb +9 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper.rb +8 -4
- data/lib/authorized_rails_scaffolds/rspec_scaffold_helper.rb +5 -4
- data/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper.rb +2 -2
- data/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper.rb +1 -1
- data/lib/authorized_rails_scaffolds/version.rb +1 -1
- data/lib/generators/authorized_rails_scaffolds/install_macros/install_macros_generator.rb +2 -1
- data/lib/generators/authorized_rails_scaffolds/install_macros/templates/devise_can_can/USAGE +1 -0
- data/lib/generators/authorized_rails_scaffolds/install_macros/templates/devise_can_can/request_macros.rb +8 -0
- data/lib/generators/authorized_rails_scaffolds/install_templates/install_templates_generator.rb +14 -0
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/_form.html.erb +2 -1
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/controller.rb +68 -35
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/helper.rb +25 -0
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/index.html.erb +15 -15
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/show.html.erb +1 -1
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/controller_spec.rb +90 -84
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/edit_spec.rb +37 -30
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/index_spec.rb +56 -51
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/new_spec.rb +33 -26
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/request_spec.rb +125 -0
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/routing_spec.rb +12 -9
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/show_spec.rb +20 -17
- data/spec/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper_spec.rb +24 -23
- data/spec/lib/authorized_rails_scaffolds/rails_helper_helper_spec.rb +66 -0
- data/spec/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper_spec.rb +42 -0
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper_spec.rb +7 -7
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper_spec.rb +14 -14
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper_spec.rb +4 -4
- metadata +16 -7
- data/lib/authorized_rails_scaffolds/resource_macros.rb +0 -81
- data/lib/authorized_rails_scaffolds/route_example_macros.rb +0 -43
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/request_spec.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<%-
|
4
|
+
# class_name
|
5
|
+
# table_name
|
6
|
+
# index_helper
|
7
|
+
|
8
|
+
t_helper = AuthorizedRailsScaffolds::RSpecIntegrationHelper.new(
|
9
|
+
:class_name => class_name,
|
10
|
+
:human_name => human_name,
|
11
|
+
:table_name => table_name
|
12
|
+
)
|
13
|
+
|
14
|
+
resource_class = t_helper.resource_class
|
15
|
+
resource_human_name = t_helper.resource_human_name
|
16
|
+
resource_array_name = t_helper.resource_array_name
|
17
|
+
resource_symbol = t_helper.resource_symbol
|
18
|
+
resource_test_var = t_helper.resource_test_var
|
19
|
+
|
20
|
+
parent_model_names = t_helper.parent_model_names
|
21
|
+
|
22
|
+
|
23
|
+
-%>
|
24
|
+
describe "<%= class_name.pluralize %>" do
|
25
|
+
|
26
|
+
# This should return the minimal set of attributes required to create a valid
|
27
|
+
# <%= resource_class %>.
|
28
|
+
def valid_create_attributes
|
29
|
+
FactoryGirl.attributes_for(<%= resource_symbol %>)
|
30
|
+
end
|
31
|
+
|
32
|
+
# This should return the minimal set of attributes required to update a valid
|
33
|
+
# <%= resource_class %>.
|
34
|
+
def valid_update_attributes
|
35
|
+
FactoryGirl.attributes_for(<%= resource_symbol %>)
|
36
|
+
end
|
37
|
+
|
38
|
+
<%- if parent_model_names.any? -%>
|
39
|
+
<%- parent_model_names.each do |parent_model| -%>
|
40
|
+
let(<%= t_helper.references_test_sym(parent_model) %>) { <%= t_helper.create_parent_resource_from_factory parent_model %> }
|
41
|
+
<%- end -%>
|
42
|
+
|
43
|
+
<%- end -%>
|
44
|
+
describe "GET <%= t_helper.example_index_path %>" do
|
45
|
+
context "as a user" do
|
46
|
+
before(:each) { sign_in_user }
|
47
|
+
it "renders a list of <%= resource_array_name %><%= t_helper.extra_comments %>" do
|
48
|
+
2.times { <%= t_helper.create_resource_from_factory %> }
|
49
|
+
get <%= t_helper.controller_index_route %>
|
50
|
+
response.status.should be(200)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "GET <%= t_helper.example_show_path %>" do
|
56
|
+
context "as a user" do
|
57
|
+
before(:each) { sign_in_user }
|
58
|
+
it "renders a <%= resource_human_name %><%= t_helper.extra_comments %>" do
|
59
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
60
|
+
get <%= t_helper.controller_show_route resource_test_var %>
|
61
|
+
response.status.should be(200)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "GET <%= t_helper.example_index_path %>/new" do
|
67
|
+
context "as a user" do
|
68
|
+
before(:each) { sign_in_user }
|
69
|
+
it "renders a form for a new <%= resource_human_name %><%= t_helper.extra_comments %>" do
|
70
|
+
get <%= t_helper.controller_new_route %>
|
71
|
+
response.status.should be(200)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "GET <%= t_helper.example_show_path %>/edit" do
|
77
|
+
context "as a user" do
|
78
|
+
before(:each) { sign_in_user }
|
79
|
+
it "renders the edit form for a <%= resource_human_name %>" do
|
80
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
81
|
+
get <%= t_helper.controller_edit_route resource_test_var %>
|
82
|
+
response.status.should be(200)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "POST <%= t_helper.example_index_path %>" do
|
88
|
+
context "as a user" do
|
89
|
+
before(:each) { sign_in_user }
|
90
|
+
it "creates and redirects to a new <%= resource_human_name %>" do
|
91
|
+
post <%= t_helper.controller_index_route %>, <%= resource_symbol %> => valid_create_attributes
|
92
|
+
response.status.should redirect_to(<%= t_helper.controller_show_route "#{resource_class}.last" %>)
|
93
|
+
follow_redirect!
|
94
|
+
response.body.should include(<%= "'#{resource_human_name} was successfully created.'" %>)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "PUT <%= t_helper.example_show_path %>" do
|
100
|
+
context "as a user" do
|
101
|
+
before(:each) { sign_in_user }
|
102
|
+
it "updates a <%= resource_human_name %> and redirects to the show url" do
|
103
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
104
|
+
put <%= t_helper.controller_show_route resource_test_var %>, <%= resource_symbol %> => valid_update_attributes
|
105
|
+
response.status.should redirect_to(<%= t_helper.controller_show_route resource_test_var %>)
|
106
|
+
follow_redirect!
|
107
|
+
response.body.should include(<%= "'#{resource_human_name} was successfully updated.'" %>)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "DELETE <%= t_helper.example_show_path %>" do
|
113
|
+
context "as a user" do
|
114
|
+
before(:each) { sign_in_user }
|
115
|
+
it "deletes a <%= resource_human_name %> and redirects to the index url" do
|
116
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
117
|
+
delete <%= t_helper.controller_show_route resource_test_var %>
|
118
|
+
response.status.should redirect_to(<%= t_helper.controller_index_route %>)
|
119
|
+
follow_redirect!
|
120
|
+
response.body.should include(<%= "'#{resource_human_name} was successfully deleted.'" %>)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/routing_spec.rb
CHANGED
@@ -23,8 +23,11 @@ t_helper = AuthorizedRailsScaffolds::RSpecScaffoldRoutingHelper.new(
|
|
23
23
|
|
24
24
|
# request_path = t_helper.request_path
|
25
25
|
resource_directory = t_helper.resource_directory
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
example_index_path = t_helper.example_index_path
|
28
|
+
example_show_path = t_helper.example_show_path
|
29
|
+
example_index_path_extra_params = t_helper.example_index_path_extra_params
|
30
|
+
example_show_path_extra_params = t_helper.example_show_path_extra_params
|
28
31
|
|
29
32
|
-%>
|
30
33
|
describe <%= t_helper.controller_class_name %> do
|
@@ -32,32 +35,32 @@ describe <%= t_helper.controller_class_name %> do
|
|
32
35
|
|
33
36
|
<% unless options[:singleton] -%>
|
34
37
|
it "routes to #index" do
|
35
|
-
get("<%=
|
38
|
+
get("<%= example_index_path %>").should route_to("<%= resource_directory %>#index"<%= example_index_path_extra_params %>)
|
36
39
|
end
|
37
40
|
|
38
41
|
<% end -%>
|
39
42
|
it "routes to #new" do
|
40
|
-
get("<%=
|
43
|
+
get("<%= example_index_path %>/new").should route_to("<%= resource_directory %>#new"<%= example_index_path_extra_params %>)
|
41
44
|
end
|
42
45
|
|
43
46
|
it "routes to #show" do
|
44
|
-
get("<%=
|
47
|
+
get("<%= example_show_path %>").should route_to("<%= resource_directory %>#show"<%= example_show_path_extra_params %>, :id => "1")
|
45
48
|
end
|
46
49
|
|
47
50
|
it "routes to #edit" do
|
48
|
-
get("<%=
|
51
|
+
get("<%= example_show_path %>/edit").should route_to("<%= resource_directory %>#edit"<%= example_show_path_extra_params %>, :id => "1")
|
49
52
|
end
|
50
53
|
|
51
54
|
it "routes to #create" do
|
52
|
-
post("<%=
|
55
|
+
post("<%= example_index_path %>").should route_to("<%= resource_directory %>#create"<%= example_index_path_extra_params %>)
|
53
56
|
end
|
54
57
|
|
55
58
|
it "routes to #update" do
|
56
|
-
put("<%=
|
59
|
+
put("<%= example_show_path %>").should route_to("<%= resource_directory %>#update"<%= example_show_path_extra_params %>, :id => "1")
|
57
60
|
end
|
58
61
|
|
59
62
|
it "routes to #destroy" do
|
60
|
-
delete("<%=
|
63
|
+
delete("<%= example_show_path %>").should route_to("<%= resource_directory %>#destroy"<%= example_show_path_extra_params %>, :id => "1")
|
61
64
|
end
|
62
65
|
|
63
66
|
end
|
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/show_spec.rb
CHANGED
@@ -11,11 +11,11 @@ t_helper = AuthorizedRailsScaffolds::RSpecScaffoldViewHelper.new(
|
|
11
11
|
|
12
12
|
resource_var = t_helper.resource_var
|
13
13
|
resource_symbol = t_helper.resource_symbol
|
14
|
-
|
15
|
-
|
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
|
-
|
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,36 +25,39 @@ standard_attributes = t_helper.standard_attributes
|
|
25
25
|
-%>
|
26
26
|
describe "<%= resource_directory %>/show" do
|
27
27
|
|
28
|
-
<%
|
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 %>, :<%=
|
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
|
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
|
-
FactoryGirl.build_stubbed(:<%= t_helper.
|
40
|
+
FactoryGirl.build_stubbed(:<%= t_helper.resource_name %><%= output_attributes.empty? ? ')' : ',' %>
|
41
41
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
42
|
-
:<%= attribute.name %> => <% if attribute.type == :references %><%= t_helper.
|
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
|
-
|
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
|
-
<%-
|
51
|
-
assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.
|
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.
|
54
|
-
|
55
|
-
@ability = Object.new
|
56
|
-
@ability.extend(CanCan::Ability)
|
57
|
-
controller.stub(:current_ability) { @ability }
|
60
|
+
assign(<%= resource_symbol %>, <%= t_helper.resource_test_name %>)
|
58
61
|
end
|
59
62
|
|
60
63
|
it "renders attributes in a <dl> as a <dt> and <dd> pair" do
|
@@ -85,7 +88,7 @@ describe "<%= resource_directory %>/show" do
|
|
85
88
|
|
86
89
|
context "with a <%= attribute.name %> reference" do
|
87
90
|
before(:each) do
|
88
|
-
<%=
|
91
|
+
<%= resource_test_name %>.<%= attribute.name %> = FactoryGirl.build_stubbed(:<%= attribute.name %>)
|
89
92
|
end
|
90
93
|
context 'without read <%= attribute.name.classify %> permissions' do
|
91
94
|
it "should not a render link to <%= attribute.name %>" do
|
@@ -3,24 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe AuthorizedRailsScaffolds::RailsErbScaffoldHelper do
|
4
4
|
include RailsErbScaffoldHelperMacros
|
5
5
|
|
6
|
-
describe '#
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
6
|
+
describe '#controller_show_route' do
|
7
|
+
it 'returns a single route to the resource' do
|
8
|
+
subject = build_rails_erb_scaffold_spec_helper :class_name => 'FooBar', :var_name => 'foo_bar'
|
9
|
+
subject.controller_new_route.should eq('new_foo_bar_path')
|
18
10
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
subject.scoped_values_for_form.should eq('[:example, :v1, @foo_bar]')
|
23
|
-
end
|
11
|
+
it 'returns appends the included value to the root' do
|
12
|
+
subject = build_rails_erb_scaffold_spec_helper :class_name => 'FooBar', :var_name => 'foo_bar'
|
13
|
+
subject.controller_show_route('@foo_bar').should eq('foo_bar_path(@foo_bar)')
|
24
14
|
end
|
25
15
|
context 'with a parent model' do
|
26
16
|
before(:each) do
|
@@ -29,18 +19,29 @@ describe AuthorizedRailsScaffolds::RailsErbScaffoldHelper do
|
|
29
19
|
end
|
30
20
|
end
|
31
21
|
context 'with no parent modules' do
|
32
|
-
|
33
|
-
subject = build_rails_erb_scaffold_spec_helper :class_name => 'FooBar', :var_name => 'foo_bar'
|
34
|
-
|
22
|
+
before(:each) do
|
23
|
+
@subject = build_rails_erb_scaffold_spec_helper :class_name => 'FooBar', :var_name => 'foo_bar'
|
24
|
+
end
|
25
|
+
it 'returns a path within the parent models' do
|
26
|
+
@subject.controller_new_route.should eq('new_parent_foo_bar_path(@parent)')
|
27
|
+
end
|
28
|
+
it 'returns a path with the resource within the parent models' do
|
29
|
+
@subject.controller_show_route('@foo_bar').should eq('parent_foo_bar_path(@parent, @foo_bar)')
|
35
30
|
end
|
36
31
|
end
|
37
32
|
context 'with a parent modules' do
|
38
|
-
|
39
|
-
subject = build_rails_erb_scaffold_spec_helper :class_name => '
|
40
|
-
|
33
|
+
before(:each) do
|
34
|
+
@subject = build_rails_erb_scaffold_spec_helper :class_name => 'Awesome::FooBar', :var_name => 'foo_bar'
|
35
|
+
end
|
36
|
+
it 'returns a path within the module and with parent models' do
|
37
|
+
@subject.controller_new_route.should eq('new_awesome_parent_foo_bar_path(@parent)')
|
38
|
+
end
|
39
|
+
it 'returns a path with the resource within the module and with parent models' do
|
40
|
+
@subject.controller_show_route('@foo_bar').should eq('awesome_parent_foo_bar_path(@parent, @foo_bar)')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
44
45
|
end
|
45
46
|
|
46
47
|
describe '#resource_var' do
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AuthorizedRailsScaffolds::RailsHelperHelper do
|
4
|
+
|
5
|
+
describe 'template values' do
|
6
|
+
context 'within nested module' do
|
7
|
+
let(:subject) do
|
8
|
+
AuthorizedRailsScaffolds::RailsHelperHelper.new(
|
9
|
+
:class_name => 'Example::FooBars',
|
10
|
+
:singular_table_name => 'example_foo_bar',
|
11
|
+
:file_name => 'foo_bars' # Helper has plural file_name
|
12
|
+
)
|
13
|
+
end
|
14
|
+
it { subject.resource_class.should eq('FooBar') }
|
15
|
+
it { subject.resource_human_name.should eq('Foo bar') }
|
16
|
+
|
17
|
+
it { subject.resource_name.should eq('foo_bar') }
|
18
|
+
it { subject.resource_var.should eq('@foo_bar') }
|
19
|
+
it { subject.resource_symbol.should eq(':foo_bar') }
|
20
|
+
|
21
|
+
it { subject.resource_array_name.should eq('foo_bars') }
|
22
|
+
it { subject.resource_array_var.should eq('@foo_bars') }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#scoped_values_for_form' do
|
27
|
+
context 'with no parent modules' do
|
28
|
+
it 'returns the resource variable' do
|
29
|
+
subject = AuthorizedRailsScaffolds::RailsHelperHelper.new(:class_name => 'FooBar', :var_name => 'foo_bar')
|
30
|
+
subject.scoped_values_for_form('@foo_bar').should eq('@foo_bar')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'with a parent modules' do
|
34
|
+
it 'returns a array with the parent module symbol and the resource variable' do
|
35
|
+
subject = AuthorizedRailsScaffolds::RailsHelperHelper.new(:class_name => 'Example::FooBar', :var_name => 'foo_bar')
|
36
|
+
subject.scoped_values_for_form('@foo_bar').should eq('[:example, @foo_bar]')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context 'with multiple parent modules' do
|
40
|
+
it 'returns a array with all parent modules as symbols and the resource variable' do
|
41
|
+
subject = AuthorizedRailsScaffolds::RailsHelperHelper.new(:class_name => 'Example::V1::FooBar', :var_name => 'foo_bar')
|
42
|
+
subject.scoped_values_for_form('@foo_bar').should eq('[:example, :v1, @foo_bar]')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context 'with a parent model' do
|
46
|
+
before(:each) do
|
47
|
+
AuthorizedRailsScaffolds.configure do |config|
|
48
|
+
config.parent_models = ['Parent']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'with no parent modules' do
|
52
|
+
it 'returns a array with the parent model and the resource variable' do
|
53
|
+
subject = AuthorizedRailsScaffolds::RailsHelperHelper.new(:class_name => 'FooBar', :var_name => 'foo_bar')
|
54
|
+
subject.scoped_values_for_form('@foo_bar').should eq('[@parent, @foo_bar]')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
context 'with a parent modules' do
|
58
|
+
it 'returns a array with the parent modules, the parent model and the resource variable' do
|
59
|
+
subject = AuthorizedRailsScaffolds::RailsHelperHelper.new(:class_name => 'Example::FooBar', :var_name => 'foo_bar')
|
60
|
+
subject.scoped_values_for_form('@foo_bar').should eq('[:example, @parent, @foo_bar]')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -3,6 +3,48 @@ require 'spec_helper'
|
|
3
3
|
describe AuthorizedRailsScaffolds::RailsScaffoldControllerHelper do
|
4
4
|
include RailsScaffoldControllerHelperMacros
|
5
5
|
|
6
|
+
describe 'template variables' do
|
7
|
+
context 'within nested module' do
|
8
|
+
let(:subject) do
|
9
|
+
build_rails_controller_spec_helper :class_name => 'Example::FooBar'
|
10
|
+
end
|
11
|
+
it { subject.resource_class.should eq('FooBar') }
|
12
|
+
it { subject.resource_human_name.should eq('Foo bar') }
|
13
|
+
it { subject.resource_symbol.should eq(':foo_bar') }
|
14
|
+
it { subject.resource_name.should eq('foo_bar') }
|
15
|
+
it { subject.resource_array_name.should eq('foo_bars') }
|
16
|
+
it { subject.resource_var.should eq('@foo_bar') }
|
17
|
+
it { subject.resource_array_var.should eq('@foo_bars') }
|
18
|
+
|
19
|
+
it { subject.example_index_path.should eq("/example/foo_bars") }
|
20
|
+
end
|
21
|
+
context 'within nested modules and parent parent models' do
|
22
|
+
let(:subject) do
|
23
|
+
AuthorizedRailsScaffolds.configure do |config|
|
24
|
+
config.parent_models = ['Parent']
|
25
|
+
end
|
26
|
+
AuthorizedRailsScaffolds::RailsScaffoldControllerHelper.new(
|
27
|
+
:class_name => 'Example::FooBar',
|
28
|
+
:human_name => 'Foo bar',
|
29
|
+
:controller_class_name => 'Example::FooBars',
|
30
|
+
:singular_table_name => 'example_foo_bar',
|
31
|
+
:file_name => 'foo_bar'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
it { subject.resource_class.should eq('FooBar') }
|
35
|
+
it { subject.resource_human_name.should eq('Foo bar') }
|
36
|
+
|
37
|
+
it { subject.resource_name.should eq('foo_bar') }
|
38
|
+
it { subject.resource_var.should eq('@foo_bar') }
|
39
|
+
it { subject.resource_symbol.should eq(':foo_bar') }
|
40
|
+
|
41
|
+
it { subject.resource_array_name.should eq('foo_bars') }
|
42
|
+
it { subject.resource_array_var.should eq('@foo_bars') }
|
43
|
+
|
44
|
+
it { subject.example_index_path.should eq("/example/parents/2/foo_bars") }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
6
48
|
describe '#application_controller_class' do
|
7
49
|
context 'with no parent modules' do
|
8
50
|
it 'returns a default ApplicationController' do
|
@@ -101,11 +101,11 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe '#
|
104
|
+
describe '#parent_model_names' do
|
105
105
|
context 'with no parent_models' do
|
106
106
|
it 'returns an empty array' do
|
107
107
|
subject = build_controller_spec_helper
|
108
|
-
subject.
|
108
|
+
subject.parent_model_names.should eq([])
|
109
109
|
end
|
110
110
|
end
|
111
111
|
context 'with a parent model' do
|
@@ -116,7 +116,7 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
116
116
|
end
|
117
117
|
it 'returns an array containing the models table name' do
|
118
118
|
subject = build_controller_spec_helper
|
119
|
-
subject.
|
119
|
+
subject.parent_model_names.should eq(['parent'])
|
120
120
|
end
|
121
121
|
end
|
122
122
|
context 'with multiple parent models' do
|
@@ -127,19 +127,19 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
127
127
|
end
|
128
128
|
it 'returns an array containing all model table names' do
|
129
129
|
subject = build_controller_spec_helper
|
130
|
-
subject.
|
130
|
+
subject.parent_model_names.should eq(['grandparent', 'parent'])
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
describe '#
|
135
|
+
describe '#resource_name' do
|
136
136
|
it 'returns the var_name' do
|
137
137
|
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
138
|
-
subject.
|
138
|
+
subject.resource_name.should eq('foo_bar')
|
139
139
|
end
|
140
140
|
it 'returns the converts class_name into underscored' do
|
141
141
|
subject = build_controller_spec_helper :class_name => 'FooBar'
|
142
|
-
subject.
|
142
|
+
subject.resource_name.should eq('foo_bar')
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|