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.
- checksums.yaml +7 -0
- data/README.md +13 -26
- data/lib/authorized_rails_scaffolds.rb +11 -2
- data/lib/authorized_rails_scaffolds/controller_macros.rb +22 -0
- data/lib/authorized_rails_scaffolds/factory_macros.rb +65 -0
- data/lib/authorized_rails_scaffolds/helper.rb +38 -115
- data/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper.rb +40 -0
- data/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper.rb +20 -0
- data/lib/authorized_rails_scaffolds/resource_macros.rb +81 -0
- data/lib/authorized_rails_scaffolds/route_example_macros.rb +43 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper.rb +17 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_helper.rb +26 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper.rb +12 -0
- data/lib/authorized_rails_scaffolds/{rspec_scaffold_generator_view_helper.rb → rspec_scaffold_view_helper.rb} +3 -2
- data/lib/authorized_rails_scaffolds/test_var_macros.rb +40 -0
- data/lib/authorized_rails_scaffolds/version.rb +1 -1
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/_form.html.erb +4 -6
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/controller.rb +50 -34
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/edit.html.erb +2 -4
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/index.html.erb +17 -18
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/new.html.erb +2 -4
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/show.html.erb +15 -17
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/controller_spec.rb +126 -101
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/edit_spec.rb +44 -39
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/index_spec.rb +73 -65
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/model_spec.rb +9 -8
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/new_spec.rb +38 -35
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/routing_spec.rb +21 -10
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/show_spec.rb +37 -20
- data/spec/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper_spec.rb +59 -0
- data/spec/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper_spec.rb +89 -0
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper_spec.rb +155 -0
- data/spec/lib/authorized_rails_scaffolds/{rspec_scaffold_generator_helper_spec.rb → rspec_scaffold_routing_helper_spec.rb} +57 -50
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper_spec.rb +86 -0
- data/spec/spec_helper.rb +5 -2
- data/spec/support/rails_erb_scaffold_helper_macros.rb +15 -0
- data/spec/support/rails_scaffold_controller_helper_macros.rb +15 -0
- data/spec/support/{rspec_scaffold_generator_helper_macros.rb → rspec_scaffold_controller_helper_macros.rb} +2 -2
- data/spec/support/rspec_scaffold_routing_helper_macros.rb +15 -0
- data/spec/support/rspec_scaffold_view_helper_macros.rb +15 -0
- metadata +66 -28
- data/lib/authorized_rails_scaffolds/rspec_scaffold_generator_helper.rb +0 -82
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/edit_spec.rb
CHANGED
@@ -2,72 +2,77 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
<%-
|
4
4
|
|
5
|
-
t_helper = AuthorizedRailsScaffolds::
|
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
|
-
|
13
|
-
|
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
|
-
|
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 "<%=
|
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(
|
30
|
+
let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
|
28
31
|
<%- else -%>
|
29
|
-
let(
|
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
|
-
|
33
|
-
|
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
|
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
|
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(
|
51
|
+
assign(<%= t_helper.parent_sym(parent_model) %>, <%= t_helper.references_test_property(parent_model) %>)
|
45
52
|
<%- end -%>
|
46
|
-
assign(
|
53
|
+
assign(<%= resource_symbol %>, <%= t_helper.resource_test_property %>)
|
47
54
|
end
|
48
55
|
|
49
|
-
it "renders the edit <%=
|
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
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
form.should have_selector("
|
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
|
70
|
+
assert_select "form[action=?][method=?]", <%= t_helper.controller_show_route resource_test_property %>, "post" do
|
65
71
|
<% for attribute in standard_attributes -%>
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
assert_select "
|
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
|
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#<%=
|
85
|
-
form.should have_selector("select#<%=
|
86
|
-
form.should have_selector("select#<%=
|
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#<%=
|
90
|
-
form.should have_selector("select#<%=
|
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
|
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#<%=
|
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#<%=
|
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#<%=
|
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#<%=
|
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#<%=
|
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 -%>
|
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/index_spec.rb
CHANGED
@@ -2,54 +2,58 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
<%-
|
4
4
|
|
5
|
-
t_helper = AuthorizedRailsScaffolds::
|
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
|
-
|
12
|
+
resource_directory = t_helper.resource_directory
|
13
13
|
parent_model_tables = t_helper.parent_model_tables
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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 "<%=
|
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(
|
29
|
+
let(<%= t_helper.references_test_sym(parent_model) %>) { FactoryGirl.build_stubbed(:<%= parent_model %>) }
|
27
30
|
<%- else -%>
|
28
|
-
let(
|
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(
|
33
|
-
FactoryGirl.build_stubbed(
|
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
|
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
|
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(
|
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
|
-
|
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 => <%=
|
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 => <%=
|
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 "<%=
|
73
|
-
it 'includes a row for each <%=
|
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.<%=
|
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.<%=
|
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 <%=
|
91
|
+
it "contains a list of <%= t_helper.resource_plural_name %>" do
|
88
92
|
render
|
89
|
-
<%
|
90
|
-
|
91
|
-
|
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
|
-
|
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
|
-
<%-
|
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
|
-
<%
|
109
|
-
<%- next
|
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 <%=
|
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
|
-
<%
|
121
|
-
<%- next unless
|
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 <%=
|
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 <%=
|
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
|
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
|
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 <%=
|
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
|
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
|
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, <%=
|
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
|
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
|
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 <%=
|
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
|
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
|
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, <%=
|
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
|
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
|
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 <%=
|
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, <%=
|
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)
|
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/model_spec.rb
CHANGED
@@ -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
|
14
|
-
it { should
|
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
|
-
<%-
|
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 -%>
|