shoulda_routing_macros 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1 +1,150 @@
1
- # ShouldaRoutingMacros
1
+ class Test::Unit::TestCase
2
+ class << self
3
+ def should_map_resource(controller, options={})
4
+ options.reverse_merge!({
5
+ :except => []
6
+ })
7
+
8
+ controller_string = controller.to_s
9
+ controller_as = options[:as] || controller_string
10
+ controller_plural = options[:plural] || controller_string.pluralize
11
+
12
+ unless Array(options[:except]).include?(:show)
13
+ should "map GET show => #{controller}" do
14
+ assert_routing controller_as, {:controller => controller_plural, :action => 'show'}
15
+ end
16
+ end
17
+
18
+ unless Array(options[:except]).include?(:new)
19
+ should "map GET new => #{controller}/new" do
20
+ assert_routing "#{controller_as}/new", {:controller => controller_plural, :action => 'new'}
21
+ end
22
+ end
23
+
24
+ unless Array(options[:except]).include?(:create)
25
+ should "map POST create => #{controller}" do
26
+ assert_routing({:path => controller_as, :method => :post}, {:controller => controller_plural, :action => 'create'})
27
+ end
28
+ end
29
+
30
+ unless Array(options[:except]).include?(:edit)
31
+ should "map GET edit => #{controller}/edit" do
32
+ assert_routing "#{controller_as}/edit", {:controller => controller_plural, :action => 'edit'}
33
+ end
34
+ end
35
+
36
+ unless Array(options[:except]).include?(:update)
37
+ should "map PUT update => #{controller}" do
38
+ assert_routing({:path => controller_as, :method => :put}, {:controller => controller_plural, :action => 'update'})
39
+ end
40
+ end
41
+
42
+ unless Array(options[:except]).include?(:destroy)
43
+ should "map DELETE destroy => #{controller}" do
44
+ assert_routing({:path => controller_as, :method => :delete}, {:controller => controller_plural, :action => 'destroy'})
45
+ end
46
+ end
47
+ end
48
+
49
+ def should_map_resources(*controllers)
50
+ options = controllers.extract_options!
51
+
52
+ controllers.each {|controller| should_map_nested_resources(controller, options)}
53
+ end
54
+
55
+ def should_map_nested_resources(*controllers)
56
+ options = controllers.extract_options!
57
+
58
+ controller = controllers.pop.to_s
59
+ controller_as = options[:as] || controller
60
+
61
+ # build controller path
62
+ real_path = ''
63
+ test_path = ''
64
+ controller_ids = {}
65
+ controllers.each do |controller_part|
66
+ controller_part = controller_part.to_s
67
+ singular = options[:parent_singular] || controller_part.singularize
68
+
69
+ real_path += "/#{controller_part}/1"
70
+ test_path += "/#{controller_part}/:#{singular}_id"
71
+ controller_ids["#{singular}_id".to_sym] = '1'
72
+ end
73
+
74
+ # Do seven basic restful actions
75
+ unless Array(options[:except]).include?(:index)
76
+ should "map GET index => #{test_path}/#{controller}" do
77
+ assert_routing "#{real_path}/#{controller_as}", {:controller => controller, :action => 'index'}.merge(controller_ids)
78
+ end
79
+ end
80
+
81
+ unless Array(options[:except]).include?(:show)
82
+ should "map GET show => #{test_path}/#{controller}/:id" do
83
+ assert_routing "#{real_path}/#{controller_as}/1", {:controller => controller, :action => 'show', :id => '1'}.merge(controller_ids)
84
+ end
85
+ end
86
+
87
+ unless Array(options[:except]).include?(:new)
88
+ should "map GET new => #{test_path}/#{controller}/new" do
89
+ assert_routing "#{real_path}/#{controller_as}/new", {:controller => controller, :action => 'new'}.merge(controller_ids)
90
+ end
91
+ end
92
+
93
+ unless Array(options[:except]).include?(:create)
94
+ should "map POST create => #{test_path}/#{controller}" do
95
+ assert_routing({:path => "#{real_path}/#{controller_as}", :method => :post}, {:controller => controller, :action => 'create'}.merge(controller_ids))
96
+ end
97
+ end
98
+
99
+ unless Array(options[:except]).include?(:edit)
100
+ should "map GET edit => #{test_path}/#{controller}/:id/edit" do
101
+ assert_routing "#{real_path}/#{controller_as}/1/edit", {:controller => controller, :action => 'edit', :id => '1'}.merge(controller_ids)
102
+ end
103
+ end
104
+
105
+ unless Array(options[:except]).include?(:update)
106
+ should "map PUT update => #{test_path}/#{controller}/:id" do
107
+ assert_routing({:path => "#{real_path}/#{controller_as}/1", :method => :put}, {:controller => controller, :action => 'update', :id => '1'}.merge(controller_ids))
108
+ end
109
+ end
110
+
111
+ unless Array(options[:except]).include?(:destroy)
112
+ should "map DELETE destroy => #{test_path}/#{controller}/:id" do
113
+ assert_routing({:path => "#{real_path}/#{controller_as}/1", :method => :delete}, {:controller => controller, :action => 'destroy', :id => '1'}.merge(controller_ids))
114
+ end
115
+ end
116
+
117
+ # Test collection routes, if any
118
+ if options[:collection]
119
+ options[:collection].each do |action, methods|
120
+ action = action.to_s
121
+
122
+ methods = [:get, :post, :put, :delete] if methods == :any
123
+ methods = [methods] unless methods.is_a?(Array)
124
+
125
+ methods.each do |method|
126
+ should "map #{method.to_s.upcase} #{action} => #{test_path}/#{controller}/#{action}" do
127
+ assert_routing({:path => "#{real_path}/#{controller_as}/#{action}", :method => method}, {:controller => controller, :action => action}.merge(controller_ids))
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ # Test member routes, if any
134
+ if options[:member]
135
+ options[:member].each do |action, methods|
136
+ action = action.to_s
137
+
138
+ methods = [:get, :post, :put, :delete] if methods == :any
139
+ methods = [methods] unless methods.is_a?(Array)
140
+
141
+ methods.each do |method|
142
+ should "map #{method.to_s.upcase} #{action} => #{test_path}/#{controller}/:id/#{action}" do
143
+ assert_routing({:path => "#{real_path}/#{controller_as}/1/#{action}", :method => method}, {:controller => controller, :action => action, :id => '1'}.merge(controller_ids))
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda_routing_macros
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jaime Bellmyer
@@ -35,7 +35,6 @@ files:
35
35
  - init.rb
36
36
  - install.rb
37
37
  - lib/shoulda_routing_macros.rb
38
- - shoulda_macros/routing_macros.rb
39
38
  - tasks/shoulda_routing_macros_tasks.rake
40
39
  - test/shoulda_routing_macros_test.rb
41
40
  - test/test_helper.rb
@@ -1,150 +0,0 @@
1
- class Test::Unit::TestCase
2
- class << self
3
- def should_map_resource(controller, options={})
4
- options.reverse_merge!({
5
- :except => []
6
- })
7
-
8
- controller_string = controller.to_s
9
- controller_as = options[:as] || controller_string
10
- controller_plural = options[:plural] || controller_string.pluralize
11
-
12
- unless Array(options[:except]).include?(:show)
13
- should "map GET show => #{controller}" do
14
- assert_routing controller_as, {:controller => controller_plural, :action => 'show'}
15
- end
16
- end
17
-
18
- unless Array(options[:except]).include?(:new)
19
- should "map GET new => #{controller}/new" do
20
- assert_routing "#{controller_as}/new", {:controller => controller_plural, :action => 'new'}
21
- end
22
- end
23
-
24
- unless Array(options[:except]).include?(:create)
25
- should "map POST create => #{controller}" do
26
- assert_routing({:path => controller_as, :method => :post}, {:controller => controller_plural, :action => 'create'})
27
- end
28
- end
29
-
30
- unless Array(options[:except]).include?(:edit)
31
- should "map GET edit => #{controller}/edit" do
32
- assert_routing "#{controller_as}/edit", {:controller => controller_plural, :action => 'edit'}
33
- end
34
- end
35
-
36
- unless Array(options[:except]).include?(:update)
37
- should "map PUT update => #{controller}" do
38
- assert_routing({:path => controller_as, :method => :put}, {:controller => controller_plural, :action => 'update'})
39
- end
40
- end
41
-
42
- unless Array(options[:except]).include?(:destroy)
43
- should "map DELETE destroy => #{controller}" do
44
- assert_routing({:path => controller_as, :method => :delete}, {:controller => controller_plural, :action => 'destroy'})
45
- end
46
- end
47
- end
48
-
49
- def should_map_resources(*controllers)
50
- options = controllers.extract_options!
51
-
52
- controllers.each {|controller| should_map_nested_resources(controller, options)}
53
- end
54
-
55
- def should_map_nested_resources(*controllers)
56
- options = controllers.extract_options!
57
-
58
- controller = controllers.pop.to_s
59
- controller_as = options[:as] || controller
60
-
61
- # build controller path
62
- real_path = ''
63
- test_path = ''
64
- controller_ids = {}
65
- controllers.each do |controller_part|
66
- controller_part = controller_part.to_s
67
- singular = options[:parent_singular] || controller_part.singularize
68
-
69
- real_path += "/#{controller_part}/1"
70
- test_path += "/#{controller_part}/:#{singular}_id"
71
- controller_ids["#{singular}_id".to_sym] = '1'
72
- end
73
-
74
- # Do seven basic restful actions
75
- unless Array(options[:except]).include?(:index)
76
- should "map GET index => #{test_path}/#{controller}" do
77
- assert_routing "#{real_path}/#{controller_as}", {:controller => controller, :action => 'index'}.merge(controller_ids)
78
- end
79
- end
80
-
81
- unless Array(options[:except]).include?(:show)
82
- should "map GET show => #{test_path}/#{controller}/:id" do
83
- assert_routing "#{real_path}/#{controller_as}/1", {:controller => controller, :action => 'show', :id => '1'}.merge(controller_ids)
84
- end
85
- end
86
-
87
- unless Array(options[:except]).include?(:new)
88
- should "map GET new => #{test_path}/#{controller}/new" do
89
- assert_routing "#{real_path}/#{controller_as}/new", {:controller => controller, :action => 'new'}.merge(controller_ids)
90
- end
91
- end
92
-
93
- unless Array(options[:except]).include?(:create)
94
- should "map POST create => #{test_path}/#{controller}" do
95
- assert_routing({:path => "#{real_path}/#{controller_as}", :method => :post}, {:controller => controller, :action => 'create'}.merge(controller_ids))
96
- end
97
- end
98
-
99
- unless Array(options[:except]).include?(:edit)
100
- should "map GET edit => #{test_path}/#{controller}/:id/edit" do
101
- assert_routing "#{real_path}/#{controller_as}/1/edit", {:controller => controller, :action => 'edit', :id => '1'}.merge(controller_ids)
102
- end
103
- end
104
-
105
- unless Array(options[:except]).include?(:update)
106
- should "map PUT update => #{test_path}/#{controller}/:id" do
107
- assert_routing({:path => "#{real_path}/#{controller_as}/1", :method => :put}, {:controller => controller, :action => 'update', :id => '1'}.merge(controller_ids))
108
- end
109
- end
110
-
111
- unless Array(options[:except]).include?(:destroy)
112
- should "map DELETE destroy => #{test_path}/#{controller}/:id" do
113
- assert_routing({:path => "#{real_path}/#{controller_as}/1", :method => :delete}, {:controller => controller, :action => 'destroy', :id => '1'}.merge(controller_ids))
114
- end
115
- end
116
-
117
- # Test collection routes, if any
118
- if options[:collection]
119
- options[:collection].each do |action, methods|
120
- action = action.to_s
121
-
122
- methods = [:get, :post, :put, :delete] if methods == :any
123
- methods = [methods] unless methods.is_a?(Array)
124
-
125
- methods.each do |method|
126
- should "map #{method.to_s.upcase} #{action} => #{test_path}/#{controller}/#{action}" do
127
- assert_routing({:path => "#{real_path}/#{controller_as}/#{action}", :method => method}, {:controller => controller, :action => action}.merge(controller_ids))
128
- end
129
- end
130
- end
131
- end
132
-
133
- # Test member routes, if any
134
- if options[:member]
135
- options[:member].each do |action, methods|
136
- action = action.to_s
137
-
138
- methods = [:get, :post, :put, :delete] if methods == :any
139
- methods = [methods] unless methods.is_a?(Array)
140
-
141
- methods.each do |method|
142
- should "map #{method.to_s.upcase} #{action} => #{test_path}/#{controller}/:id/#{action}" do
143
- assert_routing({:path => "#{real_path}/#{controller_as}/1/#{action}", :method => method}, {:controller => controller, :action => action, :id => '1'}.merge(controller_ids))
144
- end
145
- end
146
- end
147
- end
148
- end
149
- end
150
- end