remarkable_rails 3.0.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/CHANGELOG +81 -0
- data/LICENSE +20 -0
- data/README +2 -0
- data/lib/remarkable_rails/action_controller/base.rb +31 -0
- data/lib/remarkable_rails/action_controller/macro_stubs.rb +518 -0
- data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +94 -0
- data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +41 -0
- data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +119 -0
- data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +147 -0
- data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +125 -0
- data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +94 -0
- data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +108 -0
- data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +55 -0
- data/lib/remarkable_rails/action_controller.rb +22 -0
- data/lib/remarkable_rails/action_view/base.rb +7 -0
- data/lib/remarkable_rails/action_view.rb +18 -0
- data/lib/remarkable_rails/active_orm.rb +19 -0
- data/lib/remarkable_rails.rb +30 -0
- data/locale/en.yml +87 -0
- data/spec/action_controller/assign_to_matcher_spec.rb +143 -0
- data/spec/action_controller/filter_params_matcher_spec.rb +64 -0
- data/spec/action_controller/macro_stubs_spec.rb +196 -0
- data/spec/action_controller/redirect_to_matcher_spec.rb +102 -0
- data/spec/action_controller/render_template_matcher_spec.rb +251 -0
- data/spec/action_controller/respond_with_matcher_spec.rb +223 -0
- data/spec/action_controller/route_matcher_spec.rb +75 -0
- data/spec/action_controller/set_session_matcher_spec.rb +135 -0
- data/spec/action_controller/set_the_flash_matcher_spec.rb +95 -0
- data/spec/application/application.rb +15 -0
- data/spec/application/examples/_example.html.erb +0 -0
- data/spec/application/examples/example.html.erb +0 -0
- data/spec/application/examples/example.xml.builder +0 -0
- data/spec/application/examples/new.html.erb +0 -0
- data/spec/application/layouts/examples.html.erb +0 -0
- data/spec/application/projects/new.html.erb +0 -0
- data/spec/application/tasks_controller.rb +34 -0
- data/spec/functional_builder.rb +93 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +44 -0
- metadata +134 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'route_matcher' do
|
4
|
+
include FunctionalBuilder
|
5
|
+
|
6
|
+
describe 'messages' do
|
7
|
+
before(:each) do
|
8
|
+
@matcher = route(:get, '/projects', :controller => 'boo', :action => 'index')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should contain a description message' do
|
12
|
+
@matcher.description.should match(/route GET "\/projects" to\/from/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set map_to_path? message' do
|
16
|
+
@matcher.matches?(nil)
|
17
|
+
@matcher.failure_message.should match(/Expected to map/)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should set map_to_path? message' do
|
21
|
+
@matcher.stub!(:map_to_path?).and_return(true)
|
22
|
+
@matcher.matches?(nil)
|
23
|
+
@matcher.failure_message.should match(/Expected to generate params/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'matchers' do
|
28
|
+
it { should route(:get, '/projects', :controller => :projects, :action => :index) }
|
29
|
+
it { should route(:delete, '/projects/1', :controller => :projects, :action => :destroy, :id => 1) }
|
30
|
+
it { should route(:get, '/projects/new', :controller => :projects, :action => :new) }
|
31
|
+
|
32
|
+
# explicitly specify :controller
|
33
|
+
it { should route(:post, '/projects', :controller => :projects, :action => :create) }
|
34
|
+
|
35
|
+
# non-string parameter
|
36
|
+
it { should route(:get, '/projects/1', :controller => :projects, :action => :show, :id => 1) }
|
37
|
+
|
38
|
+
# string-parameter
|
39
|
+
it { should route(:put, '/projects/1', :controller => :projects, :action => :update, :id => "1") }
|
40
|
+
|
41
|
+
# failing case
|
42
|
+
it { should_not route(:get, '/projects', :controller => :projects, :action => :show) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'macros' do
|
46
|
+
should_route :get, '/projects', :controller => :projects, :action => :index
|
47
|
+
should_route :delete, '/projects/1', :controller => :projects, :action => :destroy, :id => 1
|
48
|
+
should_route :get, '/projects/new', :controller => :projects, :action => :new
|
49
|
+
|
50
|
+
# explicitly specify :controller
|
51
|
+
should_route :post, '/projects', :controller => :projects, :action => :create
|
52
|
+
|
53
|
+
# non-string parameter
|
54
|
+
should_route :get, '/projects/1', :controller => :projects, :action => :show, :id => 1
|
55
|
+
|
56
|
+
# string-parameter
|
57
|
+
should_route :put, '/projects/1', :controller => :projects, :action => :update, :id => "1"
|
58
|
+
|
59
|
+
# failing case
|
60
|
+
should_not_route :get, '/projects', :controller => :projects, :action => :show
|
61
|
+
end
|
62
|
+
|
63
|
+
describe TasksController, :type => :routing do
|
64
|
+
controller_name 'tasks'
|
65
|
+
|
66
|
+
# Test the nested routes with implicit controller
|
67
|
+
should_route :get, '/projects/5/tasks', :action => :index, :project_id => 5
|
68
|
+
should_route :post, '/projects/5/tasks', :action => :create, :project_id => 5
|
69
|
+
should_route :get, '/projects/5/tasks/1', :action => :show, :id => 1, :project_id => 5
|
70
|
+
should_route :delete, '/projects/5/tasks/1', :action => :destroy, :id => 1, :project_id => 5
|
71
|
+
should_route :get, '/projects/5/tasks/new', :action => :new, :project_id => 5
|
72
|
+
should_route :put, '/projects/5/tasks/1', :action => :update, :id => 1, :project_id => 5
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'set_session' do
|
4
|
+
include FunctionalBuilder
|
5
|
+
|
6
|
+
describe 'messages' do
|
7
|
+
before(:each) do
|
8
|
+
@matcher = set_session(:user).to(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should contain a description message' do
|
12
|
+
@matcher = set_session(:user)
|
13
|
+
@matcher.description.should == 'set session variable user'
|
14
|
+
|
15
|
+
@matcher.to(1)
|
16
|
+
@matcher.description.should == 'set session variable user to 1'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set is_not_empty? message' do
|
20
|
+
build_response
|
21
|
+
@matcher = set_session
|
22
|
+
@matcher.matches?(@controller)
|
23
|
+
@matcher.failure_message.should == 'Expected any session variable to be set, got {}'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set contains_value? message' do
|
27
|
+
build_response { session[:user] = 10 }
|
28
|
+
@matcher = set_session.to(1)
|
29
|
+
@matcher.matches?(@controller)
|
30
|
+
@matcher.failure_message.should == 'Expected any session variable to be set to 1, got {:user=>10}'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set assigned_value? message' do
|
34
|
+
build_response
|
35
|
+
@matcher = set_session(:user)
|
36
|
+
@matcher.matches?(@controller)
|
37
|
+
@matcher.failure_message.should == 'Expected session variable user to be set, got {}'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set is_equal_value? message' do
|
41
|
+
build_response { session[:user] = 2 }
|
42
|
+
@matcher.matches?(@controller)
|
43
|
+
@matcher.failure_message.should == 'Expected session variable user to be set to 1, got {:user=>2}'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'matcher' do
|
48
|
+
before(:each) do
|
49
|
+
build_response {
|
50
|
+
session[:user] = 'jose'
|
51
|
+
session[:address] = 'Avenue'
|
52
|
+
session[:true] = true
|
53
|
+
session[:false] = false
|
54
|
+
session[:nil] = nil
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
it { should set_session }
|
59
|
+
it { should set_session.to('jose') }
|
60
|
+
it { should set_session(:user) }
|
61
|
+
it { should set_session(:user).to('jose') }
|
62
|
+
|
63
|
+
it { should_not set_session.to('joseph') }
|
64
|
+
it { should_not set_session(:post) }
|
65
|
+
it { should_not set_session(:user).to('joseph') }
|
66
|
+
|
67
|
+
it { should set_session(:user){ 'jose' } }
|
68
|
+
it { should set_session(:user, :to => proc{ 'jose' }) }
|
69
|
+
|
70
|
+
it { should_not set_session(:user).to(nil) }
|
71
|
+
it { should_not set_session(:user){ 'joseph' } }
|
72
|
+
it { should_not set_session(:user, :to => proc{ 'joseph' }) }
|
73
|
+
|
74
|
+
it { should set_session(:true) }
|
75
|
+
it { should set_session(:true).to(true) }
|
76
|
+
it { should_not set_session(:true).to(false) }
|
77
|
+
|
78
|
+
it { should set_session(:false) }
|
79
|
+
it { should set_session(:false).to(false) }
|
80
|
+
it { should_not set_session(:false).to(true) }
|
81
|
+
|
82
|
+
it { should set_session(:nil) }
|
83
|
+
it { should set_session(:nil).to(nil) }
|
84
|
+
it { should_not set_session(:nil).to(true) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'macro' do
|
88
|
+
before(:each) do
|
89
|
+
build_response {
|
90
|
+
session[:user] = 'jose'
|
91
|
+
session[:address] = 'Avenue'
|
92
|
+
session[:true] = true
|
93
|
+
session[:false] = false
|
94
|
+
session[:nil] = nil
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
should_set_session
|
99
|
+
should_set_session :to => 'jose'
|
100
|
+
should_set_session :user
|
101
|
+
should_set_session :user, :to => 'jose'
|
102
|
+
|
103
|
+
should_not_set_session :to => 'joseph'
|
104
|
+
should_not_set_session :post
|
105
|
+
should_not_set_session :user, :to => 'joseph'
|
106
|
+
|
107
|
+
should_set_session(:user){ 'jose' }
|
108
|
+
should_set_session :user, :to => proc{ 'jose' }
|
109
|
+
|
110
|
+
should_not_set_session :user, :to => nil
|
111
|
+
should_not_set_session(:user){ 'joseph' }
|
112
|
+
should_not_set_session :user, :to => proc{ 'joseph' }
|
113
|
+
|
114
|
+
should_set_session :true
|
115
|
+
should_set_session :true, :to => true
|
116
|
+
should_not_set_session :true, :to => false
|
117
|
+
|
118
|
+
should_set_session :false
|
119
|
+
should_set_session :false, :to => false
|
120
|
+
should_not_set_session :false, :to => true
|
121
|
+
|
122
|
+
should_set_session :nil
|
123
|
+
should_set_session :nil, :to => nil
|
124
|
+
should_not_set_session :nil, :to => true
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'with no parameter' do
|
128
|
+
before(:each) { build_response }
|
129
|
+
|
130
|
+
should_not_set_session
|
131
|
+
it { should_not set_session }
|
132
|
+
end
|
133
|
+
|
134
|
+
generate_macro_stubs_specs_for(:set_session)
|
135
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'set_the_flash' do
|
4
|
+
include FunctionalBuilder
|
5
|
+
|
6
|
+
describe 'messages' do
|
7
|
+
before(:each) do
|
8
|
+
@matcher = set_the_flash(:notice).to('hi')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should contain a description message' do
|
12
|
+
@matcher = set_the_flash(:notice)
|
13
|
+
@matcher.description.should == 'set the flash message notice'
|
14
|
+
|
15
|
+
@matcher.to('hi')
|
16
|
+
@matcher.description.should == 'set the flash message notice to "hi"'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set is_not_empty? message' do
|
20
|
+
build_response
|
21
|
+
@matcher = set_the_flash
|
22
|
+
@matcher.matches?(@controller)
|
23
|
+
@matcher.failure_message.should == 'Expected any flash message to be set, got {}'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set contains_value? message' do
|
27
|
+
build_response { flash[:notice] = 'bye' }
|
28
|
+
@matcher = set_the_flash.to('hi')
|
29
|
+
@matcher.matches?(@controller)
|
30
|
+
@matcher.failure_message.should == 'Expected any flash message to be set to "hi", got {:notice=>"bye"}'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set assigned_value? message' do
|
34
|
+
build_response
|
35
|
+
@matcher = set_the_flash(:notice)
|
36
|
+
@matcher.matches?(@controller)
|
37
|
+
@matcher.failure_message.should == 'Expected flash message notice to be set, got {}'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set is_equal_value? message' do
|
41
|
+
build_response { flash[:notice] = 'bye' }
|
42
|
+
@matcher.matches?(@controller)
|
43
|
+
@matcher.failure_message.should == 'Expected flash message notice to be set to "hi", got {:notice=>"bye"}'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'matcher' do
|
48
|
+
before(:each) { build_response { flash[:notice] = 'jose' } }
|
49
|
+
|
50
|
+
it { should set_the_flash }
|
51
|
+
it { should set_the_flash.to('jose') }
|
52
|
+
it { should set_the_flash(:notice) }
|
53
|
+
it { should set_the_flash(:notice).to('jose') }
|
54
|
+
|
55
|
+
it { should_not set_the_flash.to('joseph') }
|
56
|
+
it { should_not set_the_flash(:error) }
|
57
|
+
it { should_not set_the_flash(:notice).to('joseph') }
|
58
|
+
|
59
|
+
it { should set_the_flash(:notice){ 'jose' } }
|
60
|
+
it { should set_the_flash(:notice, :to => proc{ 'jose' }) }
|
61
|
+
|
62
|
+
it { should_not set_the_flash(:notice).to(nil) }
|
63
|
+
it { should_not set_the_flash(:notice){ 'joseph' } }
|
64
|
+
it { should_not set_the_flash(:notice, :to => proc{ 'joseph' }) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'macro' do
|
68
|
+
before(:each) { build_response { flash[:notice] = 'jose' } }
|
69
|
+
|
70
|
+
should_set_the_flash
|
71
|
+
should_set_the_flash :to => 'jose'
|
72
|
+
should_set_the_flash :notice
|
73
|
+
should_set_the_flash :notice, :to => 'jose'
|
74
|
+
|
75
|
+
should_not_set_the_flash :to => 'joseph'
|
76
|
+
should_not_set_the_flash :error
|
77
|
+
should_not_set_the_flash :notice, :to => 'joseph'
|
78
|
+
|
79
|
+
should_set_the_flash(:notice){ 'jose' }
|
80
|
+
should_set_the_flash :notice, :to => proc{ 'jose' }
|
81
|
+
|
82
|
+
should_not_set_the_flash :notice, :to => nil
|
83
|
+
should_not_set_the_flash(:notice){ 'joseph' }
|
84
|
+
should_not_set_the_flash :notice, :to => proc{ 'joseph' }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'with no parameter' do
|
88
|
+
before(:each) { build_response }
|
89
|
+
|
90
|
+
should_not_set_the_flash
|
91
|
+
it { should_not set_the_flash }
|
92
|
+
end
|
93
|
+
|
94
|
+
generate_macro_stubs_specs_for(:set_the_flash)
|
95
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Create an application controller to satisfy rspec-rails, a dummy controller
|
2
|
+
# and define routes.
|
3
|
+
#
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
end
|
6
|
+
|
7
|
+
class Task; end
|
8
|
+
|
9
|
+
# Define routes
|
10
|
+
ActionController::Routing::Routes.draw do |map|
|
11
|
+
map.resources :projects, :has_many => :tasks
|
12
|
+
map.connect ':controller/:action/:id'
|
13
|
+
map.connect ':controller/:action/:id.:format'
|
14
|
+
end
|
15
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class TasksController < ApplicationController
|
2
|
+
filter_parameter_logging :password
|
3
|
+
|
4
|
+
def index
|
5
|
+
@tasks = Task.find(:all)
|
6
|
+
render :text => 'index'
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
render :nothing => true
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@task = Task.find(params[:id])
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
format.html { render :text => 'show' }
|
18
|
+
format.xml { render :xml => @task.to_xml }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
@task = Task.find(params[:id])
|
24
|
+
@task.destroy
|
25
|
+
|
26
|
+
flash[:notice] = 'Task deleted.'
|
27
|
+
session[:last_task_id] = 37
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html { redirect_to project_tasks_url(10) }
|
31
|
+
format.xml { head :ok }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# This is based on Shoulda model builder for Test::Unit.
|
2
|
+
#
|
3
|
+
module FunctionalBuilder
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
return unless base.name =~ /^Spec/
|
7
|
+
|
8
|
+
base.controller_name 'application'
|
9
|
+
base.integrate_views false
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
if @defined_constants
|
13
|
+
@defined_constants.each do |class_name|
|
14
|
+
Object.send(:remove_const, class_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
base.extend ClassMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_response(&block)
|
24
|
+
klass = defined?(ExamplesController) ? ExamplesController : define_controller('Examples')
|
25
|
+
block ||= lambda { render :nothing => true }
|
26
|
+
klass.class_eval { define_method(:example, &block) }
|
27
|
+
|
28
|
+
@controller = klass.new
|
29
|
+
@request = ActionController::TestRequest.new
|
30
|
+
@response = ActionController::TestResponse.new
|
31
|
+
get :example
|
32
|
+
|
33
|
+
self.class.subject { @controller }
|
34
|
+
end
|
35
|
+
|
36
|
+
def define_controller(class_name, &block)
|
37
|
+
class_name = class_name.to_s
|
38
|
+
class_name << 'Controller' unless class_name =~ /Controller$/
|
39
|
+
define_constant(class_name, ApplicationController, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_constant(class_name, base, &block)
|
43
|
+
class_name = class_name.to_s.camelize
|
44
|
+
|
45
|
+
klass = Class.new(base)
|
46
|
+
Object.const_set(class_name, klass)
|
47
|
+
|
48
|
+
klass.class_eval(&block) if block_given?
|
49
|
+
|
50
|
+
@defined_constants ||= []
|
51
|
+
@defined_constants << class_name
|
52
|
+
|
53
|
+
klass
|
54
|
+
end
|
55
|
+
|
56
|
+
module ClassMethods
|
57
|
+
def generate_macro_stubs_specs_for(matcher, *args)
|
58
|
+
stubs_args = args.dup
|
59
|
+
|
60
|
+
options = args.extract_options!
|
61
|
+
expectations_args = (args << options.merge(:with_expectations => true))
|
62
|
+
|
63
|
+
describe 'macro stubs' do
|
64
|
+
before(:each) do
|
65
|
+
@controller = TasksController.new
|
66
|
+
@request = ActionController::TestRequest.new
|
67
|
+
@response = ActionController::TestResponse.new
|
68
|
+
end
|
69
|
+
|
70
|
+
expects :new, :on => String, :with => 'ola', :returns => 'ola'
|
71
|
+
get :new
|
72
|
+
|
73
|
+
it 'should run stubs by default' do
|
74
|
+
String.should_receive(:stub!).with(:new).and_return(@mock=mock('chain'))
|
75
|
+
@mock.should_receive(:and_return).with('ola').and_return('ola')
|
76
|
+
|
77
|
+
send(matcher, *stubs_args).matches?(@controller)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should run expectations' do
|
81
|
+
String.should_receive(:should_receive).with(:new).and_return(@mock=mock('chain'))
|
82
|
+
@mock.should_receive(:with).with('ola').and_return(@mock)
|
83
|
+
@mock.should_receive(:exactly).with(1).and_return(@mock)
|
84
|
+
@mock.should_receive(:times).and_return(@mock)
|
85
|
+
@mock.should_receive(:and_return).with('ola').and_return('ola')
|
86
|
+
|
87
|
+
send(matcher, *expectations_args).matches?(@controller)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|