shoulda_routing_macros 0.1.0

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,31 @@
1
+ Shoulda Routing Macros
2
+ ====================
3
+
4
+ This is a simple plugin I plan to combine with my other macros to create a package at a later date.
5
+
6
+
7
+ Examples
8
+ ========
9
+
10
+ If your route is:
11
+
12
+ map.resources :checkens do |chickens|
13
+ chickens.resources :eggs
14
+ end
15
+
16
+ Then your tests should be:
17
+
18
+ should_map_resources :chickens
19
+ should_map_nested_resources :chickens, :eggs
20
+
21
+ If you have a singlton resource:
22
+
23
+ map.resource :one_model_to_rule_them_all
24
+
25
+ Then your test will look very similar:
26
+
27
+ should_map_resource :one_model_to_rule_them_all
28
+
29
+ It's fairly intuitive, but I'll add more documentation later.
30
+
31
+ Copyright (c) 2010 Jaime Bellmyer, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the shoulda_routing_macros plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the shoulda_routing_macros plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'ShouldaRoutingMacros'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "shoulda_routing_macros"
29
+ gemspec.summary = "easy shoulda testing of restful routes"
30
+ gemspec.description = "Routes are an important part of your application. The larger the app, the more valuable test-driven routing will be. This gem makes testing routes as easy as defining them."
31
+ gemspec.email = "ruby@kconrails.com"
32
+ gemspec.homepage = "http://github.com/bellmyer/shoulda_routing_macros"
33
+ gemspec.authors = ["Jaime Bellmyer"]
34
+ end
35
+ Jeweler::GemcutterTasks.new
36
+ rescue LoadError
37
+ puts "Jeweler not available. Install it with: gem install jeweler"
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Include hook code here
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1 @@
1
+ # ShouldaRoutingMacros
@@ -0,0 +1,150 @@
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
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :shoulda_routing_macros do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ShouldaRoutingMacrosTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoulda_routing_macros
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jaime Bellmyer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-25 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Routes are an important part of your application. The larger the app, the more valuable test-driven routing will be. This gem makes testing routes as easy as defining them.
23
+ email: ruby@kconrails.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - MIT-LICENSE
32
+ - README
33
+ - Rakefile
34
+ - VERSION
35
+ - init.rb
36
+ - install.rb
37
+ - lib/shoulda_routing_macros.rb
38
+ - shoulda_macros/routing_macros.rb
39
+ - tasks/shoulda_routing_macros_tasks.rake
40
+ - test/shoulda_routing_macros_test.rb
41
+ - test/test_helper.rb
42
+ - uninstall.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/bellmyer/shoulda_routing_macros
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: easy shoulda testing of restful routes
77
+ test_files:
78
+ - test/shoulda_routing_macros_test.rb
79
+ - test/test_helper.rb