55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/shoulda_routing_macros.rb', line 55
def should_map_nested_resources(*controllers)
options = controllers.
controller = controllers.pop.to_s
controller_as = options[:as] || controller
real_path = ''
test_path = ''
controller_ids = {}
controllers.each do |controller_part|
controller_part = controller_part.to_s
singular = options[:parent_singular] || controller_part.singularize
real_path += "/#{controller_part}/1"
test_path += "/#{controller_part}/:#{singular}_id"
controller_ids["#{singular}_id".to_sym] = '1'
end
unless Array(options[:except]).include?(:index)
should "map GET index => #{test_path}/#{controller}" do
assert_routing "#{real_path}/#{controller_as}", {:controller => controller, :action => 'index'}.merge(controller_ids)
end
end
unless Array(options[:except]).include?(:show)
should "map GET show => #{test_path}/#{controller}/:id" do
assert_routing "#{real_path}/#{controller_as}/1", {:controller => controller, :action => 'show', :id => '1'}.merge(controller_ids)
end
end
unless Array(options[:except]).include?(:new)
should "map GET new => #{test_path}/#{controller}/new" do
assert_routing "#{real_path}/#{controller_as}/new", {:controller => controller, :action => 'new'}.merge(controller_ids)
end
end
unless Array(options[:except]).include?(:create)
should "map POST create => #{test_path}/#{controller}" do
assert_routing({:path => "#{real_path}/#{controller_as}", :method => :post}, {:controller => controller, :action => 'create'}.merge(controller_ids))
end
end
unless Array(options[:except]).include?(:edit)
should "map GET edit => #{test_path}/#{controller}/:id/edit" do
assert_routing "#{real_path}/#{controller_as}/1/edit", {:controller => controller, :action => 'edit', :id => '1'}.merge(controller_ids)
end
end
unless Array(options[:except]).include?(:update)
should "map PUT update => #{test_path}/#{controller}/:id" do
assert_routing({:path => "#{real_path}/#{controller_as}/1", :method => :put}, {:controller => controller, :action => 'update', :id => '1'}.merge(controller_ids))
end
end
unless Array(options[:except]).include?(:destroy)
should "map DELETE destroy => #{test_path}/#{controller}/:id" do
assert_routing({:path => "#{real_path}/#{controller_as}/1", :method => :delete}, {:controller => controller, :action => 'destroy', :id => '1'}.merge(controller_ids))
end
end
if options[:collection]
options[:collection].each do |action, methods|
action = action.to_s
methods = [:get, :post, :put, :delete] if methods == :any
methods = [methods] unless methods.is_a?(Array)
methods.each do |method|
should "map #{method.to_s.upcase} #{action} => #{test_path}/#{controller}/#{action}" do
assert_routing({:path => "#{real_path}/#{controller_as}/#{action}", :method => method}, {:controller => controller, :action => action}.merge(controller_ids))
end
end
end
end
if options[:member]
options[:member].each do |action, methods|
action = action.to_s
methods = [:get, :post, :put, :delete] if methods == :any
methods = [methods] unless methods.is_a?(Array)
methods.each do |method|
should "map #{method.to_s.upcase} #{action} => #{test_path}/#{controller}/:id/#{action}" do
assert_routing({:path => "#{real_path}/#{controller_as}/1/#{action}", :method => method}, {:controller => controller, :action => action, :id => '1'}.merge(controller_ids))
end
end
end
end
end
|