authorized_rails_scaffolds 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/authorized_rails_scaffolds/helper.rb +3 -3
- data/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper.rb +1 -1
- data/lib/authorized_rails_scaffolds/resource_macros.rb +6 -6
- data/lib/authorized_rails_scaffolds/test_var_macros.rb +1 -1
- data/lib/authorized_rails_scaffolds/version.rb +1 -1
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper_spec.rb +39 -9
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper_spec.rb +4 -4
- data/spec/support/rails_erb_scaffold_helper_macros.rb +3 -3
- data/spec/support/rails_scaffold_controller_helper_macros.rb +3 -3
- data/spec/support/rspec_scaffold_controller_helper_macros.rb +3 -3
- data/spec/support/rspec_scaffold_routing_helper_macros.rb +3 -3
- data/spec/support/rspec_scaffold_view_helper_macros.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c307ff40cc7d76b304b65af1a46ac08010c04ebd
|
4
|
+
data.tar.gz: 2aafb9e88c59ebc6c0d616b55df02aa2181b459a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7f7f59ee4d5fbe7211fd1ac6cd062741f0e450d5f4e4ebb63fd6fc56643d98463fdc6e4239d63da783ad4e25dba3ad86edbd6c1437d0cb041f19813c459c756
|
7
|
+
data.tar.gz: d99f4cb9d11e25bdf85785d30ba56d6f575ee13c642feec2f40cff0cf8c3f7db9417f6fa2ac05b9978ed55ded60750ebe2f758a2998f23f2f6eae4d10f44242d
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Add this line to your application's Gemfile:
|
|
22
22
|
|
23
23
|
gem 'authorized_rails_scaffolds', :group => :development
|
24
24
|
|
25
|
-
Create a initializer at `config/
|
25
|
+
Create a initializer at `config/initializers/authorized_rails_scaffolds.rb` containing:
|
26
26
|
|
27
27
|
if Rails.env.development?
|
28
28
|
|
@@ -7,7 +7,7 @@ module AuthorizedRailsScaffolds
|
|
7
7
|
@var_name = options[:var_name] || options[:file_name] # Non-namespaced variable name
|
8
8
|
|
9
9
|
# Pluralized non-namespaced variable name
|
10
|
-
@plural_var_name ||= options[:plural_var_name]
|
10
|
+
@plural_var_name ||= options[:plural_var_name]
|
11
11
|
|
12
12
|
# Determine namespace prefix i.e awesome
|
13
13
|
# options[:namespace_prefix]
|
@@ -35,11 +35,11 @@ module AuthorizedRailsScaffolds
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def collection_route_prefix
|
38
|
-
@collection_route_prefix ||=
|
38
|
+
@collection_route_prefix ||= (route_prefix_values + [resource_table_name.pluralize]).join('_')
|
39
39
|
end
|
40
40
|
|
41
41
|
def member_route_prefix
|
42
|
-
@member_route_prefix ||=
|
42
|
+
@member_route_prefix ||= (route_prefix_values + [resource_table_name]).join('_')
|
43
43
|
end
|
44
44
|
|
45
45
|
def parent_variables
|
@@ -19,7 +19,7 @@ class AuthorizedRailsScaffolds::RailsErbScaffoldHelper < AuthorizedRailsScaffold
|
|
19
19
|
|
20
20
|
# Add the models
|
21
21
|
parent_model_tables.each do |parent_model|
|
22
|
-
form_argument_values <<
|
22
|
+
form_argument_values << parent_variable(parent_model)
|
23
23
|
end
|
24
24
|
|
25
25
|
form_argument_values << variable
|
@@ -8,12 +8,12 @@ module ResourceMacros
|
|
8
8
|
# Class name of the resource being tested (i.e. 'FooBar')
|
9
9
|
def resource_class
|
10
10
|
# @local_class_name
|
11
|
-
@resource_class ||= modular_class_name.split('::')[-1]
|
11
|
+
@resource_class ||= (modular_class_name.nil? ? nil : modular_class_name.split('::')[-1]) || var_name.classify
|
12
12
|
end
|
13
13
|
|
14
14
|
# Table name of the Resource being tested (i.e. foo_bar)
|
15
15
|
def resource_table_name
|
16
|
-
@resource_table_name ||= resource_class.underscore
|
16
|
+
@resource_table_name ||= (var_name || resource_class.underscore)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Symbol used to represent resource (i.e. :foo_bar)
|
@@ -23,7 +23,7 @@ module ResourceMacros
|
|
23
23
|
|
24
24
|
# Name for plural of a resource
|
25
25
|
def resource_plural_name
|
26
|
-
@resource_plural_name ||= plural_var_name ||
|
26
|
+
@resource_plural_name ||= (plural_var_name || resource_table_name.pluralize)
|
27
27
|
end
|
28
28
|
|
29
29
|
def resource_plural_sym
|
@@ -32,7 +32,7 @@ module ResourceMacros
|
|
32
32
|
|
33
33
|
# Variable resource is assigned to in a singular context (i.e. @foo_bar)
|
34
34
|
def resource_var
|
35
|
-
@resource_var_name ||= "@#{
|
35
|
+
@resource_var_name ||= "@#{resource_table_name}"
|
36
36
|
end
|
37
37
|
|
38
38
|
# Variable resource is assigned to in a plural context (i.e. @foo_bars)
|
@@ -42,7 +42,7 @@ module ResourceMacros
|
|
42
42
|
|
43
43
|
# Directory of the current resource: i.e. awesome/foo_bars
|
44
44
|
def resource_directory
|
45
|
-
@resource_directory =
|
45
|
+
@resource_directory = ((parent_module_groups || []) + [resource_plural_name]).join("/")
|
46
46
|
end
|
47
47
|
|
48
48
|
### Parent Models ###
|
@@ -70,7 +70,7 @@ module ResourceMacros
|
|
70
70
|
|
71
71
|
# The parent modules of a controller (i.e. ['Api', 'V1'])
|
72
72
|
def parent_modules
|
73
|
-
@parent_modules ||= modular_class_name.split('::')[0..-2]
|
73
|
+
@parent_modules ||= modular_class_name.nil? ? [] : modular_class_name.split('::')[0..-2]
|
74
74
|
end
|
75
75
|
|
76
76
|
# Array of symbols used for links to parents (i.e. ['api', 'v1'])
|
@@ -31,7 +31,7 @@ module TestVarMacros
|
|
31
31
|
|
32
32
|
# Generator for properties used for testing
|
33
33
|
def resource_test_property(var_number = nil)
|
34
|
-
resource_property = "test_#{
|
34
|
+
resource_property = "test_#{resource_table_name}"
|
35
35
|
resource_property = "#{resource_property}_#{var_number}" unless var_number.nil?
|
36
36
|
resource_property
|
37
37
|
end
|
@@ -56,7 +56,7 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
56
56
|
end
|
57
57
|
it 'returns a code fragment including the parent reference' do
|
58
58
|
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
59
|
-
subject.create_resource_from_factory.should eq('FactoryGirl.create(:foo_bar, :parent =>
|
59
|
+
subject.create_resource_from_factory.should eq('FactoryGirl.create(:foo_bar, :parent => parent_parent)')
|
60
60
|
end
|
61
61
|
end
|
62
62
|
context 'with multiple parent models' do
|
@@ -67,7 +67,7 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
67
67
|
end
|
68
68
|
it 'returns a code fragment including the last parent fragment' do
|
69
69
|
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
70
|
-
subject.create_resource_from_factory.should eq('FactoryGirl.create(:foo_bar, :parent =>
|
70
|
+
subject.create_resource_from_factory.should eq('FactoryGirl.create(:foo_bar, :parent => parent_parent)')
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -92,7 +92,7 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
92
92
|
end
|
93
93
|
it 'returns last parent fragment with a references to the grandparent' do
|
94
94
|
subject = build_controller_spec_helper
|
95
|
-
subject.create_parent_resource_from_factory('parent').should eq('FactoryGirl.create(:parent, :grandparent =>
|
95
|
+
subject.create_parent_resource_from_factory('parent').should eq('FactoryGirl.create(:parent, :grandparent => parent_grandparent)')
|
96
96
|
end
|
97
97
|
it 'returns the grandparent element with no references to other classes' do
|
98
98
|
subject = build_controller_spec_helper
|
@@ -132,23 +132,53 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper do
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
describe '#resource_table_name' do
|
136
|
+
it 'returns the var_name' do
|
137
|
+
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
138
|
+
subject.resource_table_name.should eq('foo_bar')
|
139
|
+
end
|
140
|
+
it 'returns the converts class_name into underscored' do
|
141
|
+
subject = build_controller_spec_helper :class_name => 'FooBar'
|
142
|
+
subject.resource_table_name.should eq('foo_bar')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#resource_symbol' do
|
147
|
+
it 'returns var_name preceeded by an :' do
|
148
|
+
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
149
|
+
subject.resource_symbol.should eq(':foo_bar')
|
150
|
+
end
|
151
|
+
it 'falls back to a underscored class_name preceeded by an :' do
|
152
|
+
subject = build_controller_spec_helper :class_name => 'FooBar', :var_name => nil
|
153
|
+
subject.resource_symbol.should eq(':foo_bar')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
135
157
|
describe '#resource_var' do
|
136
158
|
it 'returns var_name preceeded by an @' do
|
137
159
|
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
138
160
|
subject.resource_var.should eq('@foo_bar')
|
139
161
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
subject.resource_var.should eq('@foo_bar')
|
144
|
-
end
|
162
|
+
it 'falls back to a underscored class_name preceeded by an :' do
|
163
|
+
subject = build_controller_spec_helper :class_name => 'FooBar', :var_name => nil
|
164
|
+
subject.resource_var.should eq('@foo_bar')
|
145
165
|
end
|
166
|
+
# context 'with a parent module' do
|
167
|
+
# it 'falls back to using class_name if var_name is not present' do
|
168
|
+
# subject = build_controller_spec_helper :var_name => nil, :class_name => 'Example::FooBar'
|
169
|
+
# subject.resource_var.should eq('@test_foo_bar')
|
170
|
+
# end
|
171
|
+
# end
|
146
172
|
end
|
147
173
|
|
148
174
|
describe '#resource_test_var' do
|
149
175
|
it 'returns var_name preceeded by an @' do
|
150
176
|
subject = build_controller_spec_helper :var_name => 'foo_bar'
|
151
|
-
subject.resource_test_var.should eq('@
|
177
|
+
subject.resource_test_var.should eq('@test_foo_bar')
|
178
|
+
end
|
179
|
+
it 'falls back to a underscored class_name preceeded by an @' do
|
180
|
+
subject = build_controller_spec_helper :class_name => 'FooBar', :var_name => nil
|
181
|
+
subject.resource_test_var.should eq('@test_foo_bar')
|
152
182
|
end
|
153
183
|
end
|
154
184
|
|
@@ -64,22 +64,22 @@ describe AuthorizedRailsScaffolds::RSpecScaffoldViewHelper do
|
|
64
64
|
describe '#resource_test_sym' do
|
65
65
|
it 'returns var_name preceeded by an :' do
|
66
66
|
subject = build_view_spec_helper :var_name => 'foo_bar'
|
67
|
-
subject.resource_test_sym.should eq(':
|
67
|
+
subject.resource_test_sym.should eq(':test_foo_bar')
|
68
68
|
end
|
69
69
|
it 'appends a number if included' do
|
70
70
|
subject = build_view_spec_helper :var_name => 'foo_bar'
|
71
|
-
subject.resource_test_sym(2).should eq(':
|
71
|
+
subject.resource_test_sym(2).should eq(':test_foo_bar_2')
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe '#resource_test_var' do
|
76
76
|
it 'returns var_name preceeded by an @' do
|
77
77
|
subject = build_view_spec_helper :var_name => 'foo_bar'
|
78
|
-
subject.resource_test_var.should eq('@
|
78
|
+
subject.resource_test_var.should eq('@test_foo_bar')
|
79
79
|
end
|
80
80
|
it 'appends a number if included' do
|
81
81
|
subject = build_view_spec_helper :var_name => 'foo_bar'
|
82
|
-
subject.resource_test_var(2).should eq('@
|
82
|
+
subject.resource_test_var(2).should eq('@test_foo_bar_2')
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -3,9 +3,9 @@ module RailsErbScaffoldHelperMacros
|
|
3
3
|
|
4
4
|
def build_rails_erb_scaffold_spec_helper(options = {})
|
5
5
|
defaults = {
|
6
|
-
class_name: 'Scaffold::Example', # Model class name
|
7
|
-
singular_table_name: 'scaffold_example', # path and model name
|
8
|
-
file_name: 'example', # last part of singular_table_name
|
6
|
+
# class_name: 'Scaffold::Example', # Model class name
|
7
|
+
# singular_table_name: 'scaffold_example', # path and model name
|
8
|
+
# file_name: 'example', # last part of singular_table_name
|
9
9
|
attributes: [],
|
10
10
|
}
|
11
11
|
defaults.merge! options
|
@@ -3,9 +3,9 @@ module RailsScaffoldControllerHelperMacros
|
|
3
3
|
|
4
4
|
def build_rails_controller_spec_helper(options = {})
|
5
5
|
defaults = {
|
6
|
-
class_name: 'Scaffold::Example', # Model class name
|
7
|
-
singular_table_name: 'scaffold_example', # path and model name
|
8
|
-
file_name: 'example', # last part of singular_table_name
|
6
|
+
# class_name: 'Scaffold::Example', # Model class name
|
7
|
+
# singular_table_name: 'scaffold_example', # path and model name
|
8
|
+
# file_name: 'example', # last part of singular_table_name
|
9
9
|
attributes: [],
|
10
10
|
}
|
11
11
|
defaults.merge! options
|
@@ -3,9 +3,9 @@ module RSpecScaffoldControllerHelperMacros
|
|
3
3
|
|
4
4
|
def build_controller_spec_helper(args = {})
|
5
5
|
defaults = {
|
6
|
-
class_name: 'Scaffold::Example', # Model class name
|
7
|
-
singular_table_name: 'scaffold_example', # path and model name
|
8
|
-
file_name: 'example', # last part of singular_table_name
|
6
|
+
# class_name: 'Scaffold::Example', # Model class name
|
7
|
+
# singular_table_name: 'scaffold_example', # path and model name
|
8
|
+
# file_name: 'example', # last part of singular_table_name
|
9
9
|
attributes: [],
|
10
10
|
}
|
11
11
|
defaults.merge! (args)
|
@@ -3,9 +3,9 @@ module RSpecScaffoldRoutingHelperMacros
|
|
3
3
|
|
4
4
|
def build_routing_spec_helper(args = {})
|
5
5
|
defaults = {
|
6
|
-
class_name: 'Scaffold::Example', # Model class name
|
7
|
-
singular_table_name: 'scaffold_example', # path and model name
|
8
|
-
file_name: 'example', # last part of singular_table_name
|
6
|
+
# class_name: 'Scaffold::Example', # Model class name
|
7
|
+
# singular_table_name: 'scaffold_example', # path and model name
|
8
|
+
# file_name: 'example', # last part of singular_table_name
|
9
9
|
attributes: [],
|
10
10
|
}
|
11
11
|
defaults.merge! (args)
|
@@ -3,9 +3,9 @@ module RSpecScaffoldViewHelperMacros
|
|
3
3
|
|
4
4
|
def build_view_spec_helper(args = {})
|
5
5
|
defaults = {
|
6
|
-
class_name: 'Scaffold::Example', # Model class name
|
7
|
-
singular_table_name: 'scaffold_example', # path and model name
|
8
|
-
file_name: 'example', # last part of singular_table_name
|
6
|
+
# class_name: 'Scaffold::Example', # Model class name
|
7
|
+
# singular_table_name: 'scaffold_example', # path and model name
|
8
|
+
# file_name: 'example', # last part of singular_table_name
|
9
9
|
attributes: [],
|
10
10
|
}
|
11
11
|
defaults.merge! (args)
|