shoulda_routing 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +19 -0
- data/features/multiple_resources.feature +26 -0
- data/features/nested_resources.feature +30 -0
- data/features/resources.feature +27 -0
- data/features/resources_with_options.feature +42 -0
- data/features/step_definitions/resources_steps.rb +69 -0
- data/features/support/env.rb +6 -0
- data/lib/shoulda_routing.rb +20 -0
- data/lib/shoulda_routing/dsl.rb +8 -0
- data/lib/shoulda_routing/resources/base.rb +70 -0
- data/lib/shoulda_routing/resources/dsl.rb +7 -0
- data/lib/shoulda_routing/resources/method.rb +12 -0
- data/lib/shoulda_routing/routes/helpers.rb +27 -0
- data/lib/shoulda_routing/routes/spec.rb +30 -0
- data/lib/shoulda_routing/routes/stack.rb +5 -0
- data/lib/shoulda_routing/version.rb +3 -0
- data/shoulda_routing.gemspec +28 -0
- data/spec/shoulda_routing/dsl_spec.rb +7 -0
- data/spec/shoulda_routing/routes/helpers_spec.rb +51 -0
- data/spec/shoulda_routing/routes/stack_spec.rb +9 -0
- data/spec/shoulda_routing_spec.rb +4 -0
- data/spec/spec_helper.rb +11 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 832b942a3e7e0ab735e347c59bafe3ec73d35c2e
|
4
|
+
data.tar.gz: b0482ed38c91c2b2b2a440bdaa5629946497d829
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9500058f252a20feb176b13ff62acdaec1a56ba0af67f35f3718cb0019eb918cc46e996324ecd20d1722daa1baacd87477b77f64766610397c0474ab11a7d7ba
|
7
|
+
data.tar.gz: cb726bd1d77d8efe297eb34b043cba391233598a2f786f768aa75360a022af3d1622ff790ed1742450b2b3c3d0db9b99d7e57b95c4868009cae6c0ecc62f6e58
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alejandro Gutiérrez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# ShouldaRouting [![Build Status](https://travis-ci.org/alejandrogutierrez/shoulda_routing.png?branch=master)](https://travis-ci.org/alejandrogutierrez/shoulda_routing) [![Coverage Status](https://coveralls.io/repos/alejandrogutierrez/shoulda_routing/badge.png)](https://coveralls.io/r/alejandrogutierrez/shoulda_routing)
|
2
|
+
|
3
|
+
This gem aims to provide a simple DSL that looks like the rails routes DSL that is used in the routes.rb file.
|
4
|
+
This requires the [RSpec](https://github.com/rspec/rspec-rails) testing framework.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'shoulda_routing'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install shoulda_routing
|
19
|
+
|
20
|
+
## Basic usage
|
21
|
+
|
22
|
+
In your routes.rb file:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
YourApp::Application.routes.draw do
|
26
|
+
resources :users
|
27
|
+
resources :posts, :accounts, :roles
|
28
|
+
|
29
|
+
resources :countries do
|
30
|
+
resources :states, :cities, except: :destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
resources :comments, only: [:index, :show]
|
34
|
+
resources :parents, controller: :users
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
In your routing_spec.rb file:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'spec_helper'
|
42
|
+
|
43
|
+
describe "Routes" do
|
44
|
+
resources :users
|
45
|
+
resources :posts, :accounts, :roles
|
46
|
+
|
47
|
+
resources :countries do
|
48
|
+
resources :states, :cities, except: :destroy
|
49
|
+
end
|
50
|
+
|
51
|
+
resources :comments, only: [:index, :show]
|
52
|
+
resources :parents, controller: :users
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
## TO-DO
|
57
|
+
|
58
|
+
* Support namespaces
|
59
|
+
* Support member and collection routes.
|
60
|
+
* Support single resources (get, post, put, delete) actions.
|
61
|
+
|
62
|
+
## Testing
|
63
|
+
|
64
|
+
To run the test suite you should run the default rake task:
|
65
|
+
|
66
|
+
$ bundle exec rake
|
67
|
+
|
68
|
+
To run the unit tests:
|
69
|
+
|
70
|
+
$ bundle exec rake spec:unit
|
71
|
+
|
72
|
+
To run the integration tests:
|
73
|
+
|
74
|
+
$ bundle exec cucumber
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
namespace :spec do
|
4
|
+
desc "Runs unit tests"
|
5
|
+
task :unit do
|
6
|
+
system("bundle exec rspec")
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Run all tests"
|
10
|
+
task :all do
|
11
|
+
Rake.application['spec:unit'].invoke
|
12
|
+
raise "Unit testing failed!" unless $?.exitstatus == 0
|
13
|
+
|
14
|
+
system("bundle exec cucumber")
|
15
|
+
raise "Integration testing failed!" unless $?.exitstatus == 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task default: 'spec:all'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Feature: Test multiple resources
|
2
|
+
|
3
|
+
Background:
|
4
|
+
When I generate a new rails application
|
5
|
+
And I generate resources "user post comment like"
|
6
|
+
And I configure the application to use rspec-rails
|
7
|
+
And I run the rspec generator
|
8
|
+
And I configure the application to use "shoulda_routing"
|
9
|
+
|
10
|
+
Scenario: Test multiple resources
|
11
|
+
Given I write to "config/routes.rb" with:
|
12
|
+
"""
|
13
|
+
TestApp::Application.routes.draw do
|
14
|
+
resources :users, :posts, :comments
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
And I write to "spec/routing/routing_spec.rb" with:
|
18
|
+
"""
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe 'Routes' do
|
22
|
+
resources :users, :posts, :comments, :likes
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
When I run routing specs
|
26
|
+
Then the output should contain "28 examples, 7 failures"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: Test nested resources
|
2
|
+
|
3
|
+
Background:
|
4
|
+
When I generate a new rails application
|
5
|
+
And I generate resources "user post comment"
|
6
|
+
And I configure the application to use rspec-rails
|
7
|
+
And I run the rspec generator
|
8
|
+
And I configure the application to use "shoulda_routing"
|
9
|
+
|
10
|
+
Scenario: Test nested resources
|
11
|
+
Given I write to "config/routes.rb" with:
|
12
|
+
"""
|
13
|
+
TestApp::Application.routes.draw do
|
14
|
+
resources :users do
|
15
|
+
resources :posts
|
16
|
+
end
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
And I write to "spec/routing/routing_spec.rb" with:
|
20
|
+
"""
|
21
|
+
require 'spec_helper'
|
22
|
+
|
23
|
+
describe 'Routes' do
|
24
|
+
resources :users do
|
25
|
+
resources :posts, :comments
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"""
|
29
|
+
When I run routing specs
|
30
|
+
Then the output should contain "21 examples, 7 failures"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Test resources
|
2
|
+
|
3
|
+
Background:
|
4
|
+
When I generate a new rails application
|
5
|
+
And I generate resources "user post"
|
6
|
+
And I configure the application to use rspec-rails
|
7
|
+
And I run the rspec generator
|
8
|
+
And I configure the application to use "shoulda_routing"
|
9
|
+
|
10
|
+
Scenario: Test resources
|
11
|
+
Given I write to "config/routes.rb" with:
|
12
|
+
"""
|
13
|
+
TestApp::Application.routes.draw do
|
14
|
+
resources :users
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
And I write to "spec/routing/routing_spec.rb" with:
|
18
|
+
"""
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe 'Routes' do
|
22
|
+
resources :users
|
23
|
+
resources :posts
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run routing specs
|
27
|
+
Then the output should contain "14 examples, 7 failures"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Feature: Test resources with options
|
2
|
+
|
3
|
+
Background:
|
4
|
+
When I generate a new rails application
|
5
|
+
And I generate resources "user post comment like"
|
6
|
+
And I configure the application to use rspec-rails
|
7
|
+
And I run the rspec generator
|
8
|
+
And I configure the application to use "shoulda_routing"
|
9
|
+
|
10
|
+
Scenario: Add resources options
|
11
|
+
Given I write to "config/routes.rb" with:
|
12
|
+
"""
|
13
|
+
TestApp::Application.routes.draw do
|
14
|
+
resources :posts, except: [:destroy, :update]
|
15
|
+
|
16
|
+
resources :users do
|
17
|
+
resources :posts, :comments, except: :destroy
|
18
|
+
resources :likes, only: :index
|
19
|
+
end
|
20
|
+
|
21
|
+
resources :parents, controller: :users
|
22
|
+
resources :observations
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
And I write to "spec/routing/routing_spec.rb" with:
|
26
|
+
"""
|
27
|
+
require 'spec_helper'
|
28
|
+
|
29
|
+
describe 'Routes' do
|
30
|
+
resources :posts, except: [:destroy, :update]
|
31
|
+
|
32
|
+
resources :users do
|
33
|
+
resources :posts, :comments, except: [:destroy, :show]
|
34
|
+
resources :likes, only: :destroy
|
35
|
+
end
|
36
|
+
|
37
|
+
resources :parents, controller: :users
|
38
|
+
resources :observations, controller: :comments
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
When I run routing specs
|
42
|
+
Then the output should contain "49 examples, 11 failures"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
2
|
+
APP_NAME = 'test_app'
|
3
|
+
|
4
|
+
|
5
|
+
When 'I generate a new rails application' do
|
6
|
+
steps %{
|
7
|
+
When I run `bundle exec rails new #{APP_NAME} --skip-bundle`
|
8
|
+
And I cd to "#{APP_NAME}"
|
9
|
+
And I install gems
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I generate resources "([^\"]+)"$/ do |resources|
|
14
|
+
resources.split(" ").each do |resource|
|
15
|
+
steps %{
|
16
|
+
When I write to "app/controllers/#{resource.pluralize}_controller.rb" with:
|
17
|
+
"""
|
18
|
+
class #{resource.pluralize.camelcase}Controller < ApplicationController
|
19
|
+
def index; end
|
20
|
+
def show; end
|
21
|
+
def edit; end
|
22
|
+
def update; end
|
23
|
+
def create; end
|
24
|
+
def new; end
|
25
|
+
def destroy; end
|
26
|
+
end
|
27
|
+
"""
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
When /^I configure the application to use "([^\"]+)"$/ do |name|
|
33
|
+
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
34
|
+
steps %{And I install gems}
|
35
|
+
end
|
36
|
+
|
37
|
+
When 'I configure the application to use rspec-rails' do
|
38
|
+
append_to_gemfile %q(gem 'rspec-rails', '~> 2.14.0')
|
39
|
+
steps %{When I install gems}
|
40
|
+
end
|
41
|
+
|
42
|
+
When /^I install gems$/ do
|
43
|
+
steps %{When I run `bundle install --local`}
|
44
|
+
end
|
45
|
+
|
46
|
+
When 'I run the rspec generator' do
|
47
|
+
steps %{When I successfully run `rails generate rspec:install`}
|
48
|
+
end
|
49
|
+
|
50
|
+
When 'I run routing specs' do
|
51
|
+
steps %{When I successfully run `bundle exec rspec spec/routing/routing_spec.rb --failure-exit-code 0`}
|
52
|
+
end
|
53
|
+
|
54
|
+
module FileHelpers
|
55
|
+
def append_to(path, contents)
|
56
|
+
in_current_dir do
|
57
|
+
File.open(path, 'a') do |file|
|
58
|
+
file.puts
|
59
|
+
file.puts contents
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def append_to_gemfile(contents)
|
65
|
+
append_to('Gemfile', contents)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
World(FileHelpers)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ShouldaRouting
|
2
|
+
autoload :DSL, 'shoulda_routing/dsl.rb'
|
3
|
+
autoload :VERSION, 'shoulda_routing/version.rb'
|
4
|
+
|
5
|
+
module Resources
|
6
|
+
autoload :Base, 'shoulda_routing/resources/base.rb'
|
7
|
+
autoload :DSL, 'shoulda_routing/resources/dsl.rb'
|
8
|
+
autoload :Method, 'shoulda_routing/resources/method.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
module Routes
|
12
|
+
autoload :Spec, 'shoulda_routing/routes/spec.rb'
|
13
|
+
autoload :Helpers, 'shoulda_routing/routes/helpers.rb'
|
14
|
+
autoload :STACK, 'shoulda_routing/routes/stack.rb'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if defined? RSpec
|
19
|
+
RSpec.configure{ |config| config.extend ShouldaRouting::DSL }
|
20
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module ShouldaRouting
|
2
|
+
module Resources
|
3
|
+
class Base
|
4
|
+
include Routes::Helpers
|
5
|
+
|
6
|
+
attr_accessor :current, :options, :block
|
7
|
+
|
8
|
+
def initialize *args, &block
|
9
|
+
@options = args.extract_options!
|
10
|
+
@current = args
|
11
|
+
@block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def test!
|
15
|
+
Routes::STACK.push(current)
|
16
|
+
|
17
|
+
route_permutations(Routes::STACK).each do |stack|
|
18
|
+
specs_for(routeable_actions, stack)
|
19
|
+
specs_for(unrouteable_actions, stack, :not_to)
|
20
|
+
end
|
21
|
+
|
22
|
+
DSL.instance_eval(&block) if block
|
23
|
+
Routes::STACK.pop
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def specs_for actions, stack, spec_method = :to
|
29
|
+
actions.each do |action, args|
|
30
|
+
Routes::Spec.execute do |config|
|
31
|
+
config.via = args[:via]
|
32
|
+
config.path = route_path(stack, suffix: args[:path])
|
33
|
+
config.controller = options[:controller] || stack.last
|
34
|
+
config.action = action
|
35
|
+
config.params = route_params(stack, args[:params] || {})
|
36
|
+
config.method = spec_method
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def actions
|
42
|
+
{
|
43
|
+
:index => { via: :get },
|
44
|
+
:create => { via: :post },
|
45
|
+
:new => { via: :get, path: "/new" },
|
46
|
+
:edit => { via: :get, path: "/1/edit", params: { id: "1" }},
|
47
|
+
:show => { via: :get, path: "/1", params: { id: "1" }},
|
48
|
+
:update => { via: :put, path: "/1", params: { id: "1" }},
|
49
|
+
:destroy => { via: :delete, path: "/1", params: { id: "1" }}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def routeable_actions
|
54
|
+
@routeable_actions ||= begin
|
55
|
+
routeable_actions = actions.keys
|
56
|
+
routeable_actions = actions.keys & Array(options[:only]) if options[:only]
|
57
|
+
routeable_actions = actions.keys - Array(options[:except]) if options[:except]
|
58
|
+
actions.select{ |action, args| routeable_actions.include?(action) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def unrouteable_actions
|
63
|
+
@unrouteable_actions ||= begin
|
64
|
+
actions.select{ |action, args| !routeable_actions.include?(action) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ShouldaRouting
|
2
|
+
module Routes
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
# Returns a string path according to an array.
|
6
|
+
def route_path stack, options = {}
|
7
|
+
"/#{stack.join("/1/")}" + options[:suffix].to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns the combinations according to an array passed by param.
|
11
|
+
# This is in order to generate all the nested routes.
|
12
|
+
def route_permutations stack
|
13
|
+
stack.inject(&:product).map{|e| e.flatten rescue [e]}
|
14
|
+
end
|
15
|
+
|
16
|
+
def route_params stack, options = {}
|
17
|
+
params = {}
|
18
|
+
stack[0...stack.size - 1].each do |resource|
|
19
|
+
params[:"#{resource.to_s.singularize}_id"] = "1"
|
20
|
+
end
|
21
|
+
params.merge!(options)
|
22
|
+
params
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ShouldaRouting
|
2
|
+
module Routes
|
3
|
+
class Spec
|
4
|
+
|
5
|
+
attr_accessor :via, :path, :controller, :action, :params, :method
|
6
|
+
|
7
|
+
def test!
|
8
|
+
via = @via || :get
|
9
|
+
path = @path || "/"
|
10
|
+
controller = @controller || ""
|
11
|
+
action = @action || :index
|
12
|
+
params = @params || {}
|
13
|
+
method = @method || :to
|
14
|
+
|
15
|
+
RSpec::Core::DSL.describe type: :routing do
|
16
|
+
it "routes to #{path}" do
|
17
|
+
expect(via => path).send method, route_to("#{controller}##{action}", params)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.execute
|
23
|
+
generator = self.new
|
24
|
+
yield(generator) if block_given?
|
25
|
+
generator.test!
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shoulda_routing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shoulda_routing"
|
8
|
+
spec.version = ShouldaRouting::VERSION
|
9
|
+
spec.authors = ["Alejandro Gutiérrez"]
|
10
|
+
spec.email = ["alejandrodevs@gmail.com"]
|
11
|
+
spec.description = "A simple and easy DSL to test rails routes."
|
12
|
+
spec.summary = "A simple DSL to test rails routes."
|
13
|
+
spec.homepage = "https://github.com/alejandrogutierrez/shoulda_routing"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'rails', '~> 4.0.0'
|
22
|
+
spec.add_development_dependency 'aruba', '~> 0.5.3'
|
23
|
+
spec.add_development_dependency 'rspec-rails', '~> 2.14.0'
|
24
|
+
spec.add_development_dependency 'cucumber', '~> 1.3.8'
|
25
|
+
spec.add_development_dependency 'simplecov', '~> 0.7.1'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ShouldaRouting
|
4
|
+
module Routes
|
5
|
+
describe Helpers do
|
6
|
+
let!(:subject){ Class.send(:include, described_class).tap(&:new) }
|
7
|
+
|
8
|
+
describe "#route_path" do
|
9
|
+
it "returns string path accoring to an array" do
|
10
|
+
stack = [:users, :posts, :likes]
|
11
|
+
expected = "/users/1/posts/1/likes"
|
12
|
+
expect(subject.route_path(stack)).to eq(expected)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#route_permutations" do
|
17
|
+
it "returns permutations accoring to an array" do
|
18
|
+
stack = [[1, 2]]
|
19
|
+
expected = [[1], [2]]
|
20
|
+
expect(subject.route_permutations(stack)).to eq(expected)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns permutations accoring to an array" do
|
24
|
+
stack = [[1, 2], [3, 4]]
|
25
|
+
expected = [[1, 3], [1, 4], [2, 3], [2, 4]]
|
26
|
+
expect(subject.route_permutations(stack)).to eq(expected)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns permutations accoring to an array" do
|
30
|
+
stack = [[1, 2], [3]]
|
31
|
+
expected = [[1, 3], [2, 3]]
|
32
|
+
expect(subject.route_permutations(stack)).to eq(expected)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns permutations accoring to an array" do
|
36
|
+
stack = [[1, 2], [3], [4, 5]]
|
37
|
+
expected = [[1, 3, 4], [1, 3, 5], [2, 3, 4], [2, 3, 5]]
|
38
|
+
expect(subject.route_permutations(stack)).to eq(expected)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#route_params" do
|
43
|
+
it "returns params accoring to an array" do
|
44
|
+
stack = [:users, :posts, :likes]
|
45
|
+
expected = {user_id: "1", post_id: "1"}
|
46
|
+
expect(subject.route_params(stack)).to eq(expected)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shoulda_routing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alejandro Gutiérrez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aruba
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cucumber
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.8
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.8
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.7.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.7.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A simple and easy DSL to test rails routes.
|
112
|
+
email:
|
113
|
+
- alejandrodevs@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- features/multiple_resources.feature
|
125
|
+
- features/nested_resources.feature
|
126
|
+
- features/resources.feature
|
127
|
+
- features/resources_with_options.feature
|
128
|
+
- features/step_definitions/resources_steps.rb
|
129
|
+
- features/support/env.rb
|
130
|
+
- lib/shoulda_routing.rb
|
131
|
+
- lib/shoulda_routing/dsl.rb
|
132
|
+
- lib/shoulda_routing/resources/base.rb
|
133
|
+
- lib/shoulda_routing/resources/dsl.rb
|
134
|
+
- lib/shoulda_routing/resources/method.rb
|
135
|
+
- lib/shoulda_routing/routes/helpers.rb
|
136
|
+
- lib/shoulda_routing/routes/spec.rb
|
137
|
+
- lib/shoulda_routing/routes/stack.rb
|
138
|
+
- lib/shoulda_routing/version.rb
|
139
|
+
- shoulda_routing.gemspec
|
140
|
+
- spec/shoulda_routing/dsl_spec.rb
|
141
|
+
- spec/shoulda_routing/routes/helpers_spec.rb
|
142
|
+
- spec/shoulda_routing/routes/stack_spec.rb
|
143
|
+
- spec/shoulda_routing_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: https://github.com/alejandrogutierrez/shoulda_routing
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.0.0
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: A simple DSL to test rails routes.
|
169
|
+
test_files:
|
170
|
+
- features/multiple_resources.feature
|
171
|
+
- features/nested_resources.feature
|
172
|
+
- features/resources.feature
|
173
|
+
- features/resources_with_options.feature
|
174
|
+
- features/step_definitions/resources_steps.rb
|
175
|
+
- features/support/env.rb
|
176
|
+
- spec/shoulda_routing/dsl_spec.rb
|
177
|
+
- spec/shoulda_routing/routes/helpers_spec.rb
|
178
|
+
- spec/shoulda_routing/routes/stack_spec.rb
|
179
|
+
- spec/shoulda_routing_spec.rb
|
180
|
+
- spec/spec_helper.rb
|