rspec-rails 2.5.0 → 2.6.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/.gitignore +10 -5
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/README.md +2 -0
- data/README_DEV.md +43 -0
- data/Rakefile +72 -31
- data/Thorfile +33 -18
- data/features/.nav +2 -0
- data/features/Autotest.md +7 -0
- data/features/Changelog.md +26 -2
- data/features/Generators.md +1 -1
- data/features/GettingStarted.md +45 -1
- data/features/Upgrade.md +13 -12
- data/features/controller_specs/README.md +18 -10
- data/features/controller_specs/anonymous_controller.feature +5 -5
- data/features/controller_specs/controller_spec.feature +1 -2
- data/features/controller_specs/isolation_from_views.feature +49 -3
- data/features/controller_specs/render_views.feature +3 -3
- data/features/helper_specs/helper_spec.feature +3 -3
- data/features/mailer_specs/url_helpers.feature +2 -2
- data/features/matchers/new_record_matcher.feature +1 -43
- data/features/matchers/redirect_to_matcher.feature +3 -3
- data/features/matchers/render_template_matcher.feature +12 -9
- data/features/mocks/mock_model.feature +21 -5
- data/features/mocks/stub_model.feature +2 -2
- data/features/model_specs/errors_on.feature +1 -1
- data/features/model_specs/transactional_examples.feature +10 -5
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +2 -1
- data/features/routing_specs/be_routable_matcher.feature +5 -5
- data/features/routing_specs/named_routes.feature +1 -1
- data/features/routing_specs/route_to_matcher.feature +28 -8
- data/features/step_definitions/additional_cli_steps.rb +1 -1
- data/features/support/env.rb +7 -19
- data/features/view_specs/inferred_controller_path.feature +3 -3
- data/features/view_specs/stub_template.feature +2 -2
- data/features/view_specs/view_spec.feature +16 -35
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/base.rb +58 -0
- data/gemfiles/rails-3-0-stable +6 -0
- data/gemfiles/rails-3.0.0 +5 -0
- data/gemfiles/rails-3.0.1 +5 -0
- data/gemfiles/rails-3.0.2 +5 -0
- data/gemfiles/rails-3.0.3 +5 -0
- data/gemfiles/rails-3.0.4 +5 -0
- data/gemfiles/rails-3.0.5 +5 -0
- data/gemfiles/rails-3.0.6 +5 -0
- data/gemfiles/rails-3.0.7 +5 -0
- data/gemfiles/rails-3.1.0.beta1 +5 -0
- data/gemfiles/rails-master +7 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +20 -2
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +86 -54
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +7 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -5
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec/rails/example/controller_example_group.rb +12 -22
- data/lib/rspec/rails/example/helper_example_group.rb +0 -5
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -9
- data/lib/rspec/rails/example/request_example_group.rb +0 -25
- data/lib/rspec/rails/example/routing_example_group.rb +1 -0
- data/lib/rspec/rails/example/view_example_group.rb +7 -6
- data/lib/rspec/rails/matchers/routing_matchers.rb +23 -2
- data/lib/rspec/rails/mocks.rb +3 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +29 -0
- data/lib/rspec/rails/vendor/webrat.rb +33 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +24 -8
- data/lib/rspec/rails.rb +2 -2
- data/rspec-rails.gemspec +5 -36
- data/spec/autotest/rails_rspec2_spec.rb +2 -7
- data/spec/rspec/rails/example/controller_example_group_spec.rb +25 -0
- data/spec/rspec/rails/matchers/route_to_spec.rb +15 -0
- data/spec/rspec/rails/mocks/ar_classes.rb +5 -2
- data/spec/rspec/rails/view_rendering_spec.rb +0 -6
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +9 -1
- data/templates/run_specs.rb +2 -2
- metadata +44 -65
- data/Gemfile-3-0-stable +0 -6
- data/Gemfile-3.0.0 +0 -3
- data/Gemfile-3.0.3 +0 -3
- data/Gemfile-base +0 -38
- data/Gemfile-master +0 -5
- data/lib/rspec/rails/browser_simulators.rb +0 -30
- data/specs.watchr +0 -59
- data/templates/Gemfile-base +0 -17
|
@@ -16,12 +16,12 @@ Feature: view spec
|
|
|
16
16
|
|
|
17
17
|
render
|
|
18
18
|
|
|
19
|
-
rendered.should
|
|
20
|
-
rendered.should
|
|
19
|
+
rendered.should =~ /slicer/
|
|
20
|
+
rendered.should =~ /dicer/
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
"""
|
|
24
|
-
When I run
|
|
24
|
+
When I run `rspec spec/views`
|
|
25
25
|
Then the examples should all pass
|
|
26
26
|
|
|
27
27
|
Scenario: passing spec with before and nesting
|
|
@@ -42,13 +42,13 @@ Feature: view spec
|
|
|
42
42
|
it "displays both widgets" do
|
|
43
43
|
render
|
|
44
44
|
|
|
45
|
-
rendered.should
|
|
46
|
-
rendered.should
|
|
45
|
+
rendered.should =~ /slicer/
|
|
46
|
+
rendered.should =~ /dicer/
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
"""
|
|
51
|
-
When I run
|
|
51
|
+
When I run `rspec spec/views`
|
|
52
52
|
Then the examples should all pass
|
|
53
53
|
|
|
54
54
|
Scenario: passing spec with explicit template rendering
|
|
@@ -62,7 +62,7 @@ Feature: view spec
|
|
|
62
62
|
|
|
63
63
|
render :template => "widgets/widget.html.erb"
|
|
64
64
|
|
|
65
|
-
rendered.should
|
|
65
|
+
rendered.should =~ /slicer/
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
"""
|
|
@@ -70,7 +70,7 @@ Feature: view spec
|
|
|
70
70
|
"""
|
|
71
71
|
<h2><%= @widget.name %></h2>
|
|
72
72
|
"""
|
|
73
|
-
When I run
|
|
73
|
+
When I run `rspec spec/views`
|
|
74
74
|
Then the examples should all pass
|
|
75
75
|
|
|
76
76
|
Scenario: passing spec with rendering of locals in a partial
|
|
@@ -84,7 +84,7 @@ Feature: view spec
|
|
|
84
84
|
|
|
85
85
|
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
|
|
86
86
|
|
|
87
|
-
rendered.should
|
|
87
|
+
rendered.should =~ /slicer/
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
"""
|
|
@@ -92,7 +92,7 @@ Feature: view spec
|
|
|
92
92
|
"""
|
|
93
93
|
<h3><%= widget.name %></h3>
|
|
94
94
|
"""
|
|
95
|
-
When I run
|
|
95
|
+
When I run `rspec spec/views`
|
|
96
96
|
Then the examples should all pass
|
|
97
97
|
|
|
98
98
|
Scenario: passing spec with rendering of locals in an implicit partial
|
|
@@ -106,7 +106,7 @@ Feature: view spec
|
|
|
106
106
|
|
|
107
107
|
render "widgets/widget", :widget => widget
|
|
108
108
|
|
|
109
|
-
rendered.should
|
|
109
|
+
rendered.should =~ /slicer/
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
"""
|
|
@@ -114,7 +114,7 @@ Feature: view spec
|
|
|
114
114
|
"""
|
|
115
115
|
<h3><%= widget.name %></h3>
|
|
116
116
|
"""
|
|
117
|
-
When I run
|
|
117
|
+
When I run `rspec spec/views`
|
|
118
118
|
Then the examples should all pass
|
|
119
119
|
|
|
120
120
|
Scenario: passing spec with rendering of text
|
|
@@ -127,30 +127,11 @@ Feature: view spec
|
|
|
127
127
|
|
|
128
128
|
render :text => "This is directly rendered"
|
|
129
129
|
|
|
130
|
-
rendered.should
|
|
130
|
+
rendered.should =~ /directly rendered/
|
|
131
131
|
end
|
|
132
132
|
end
|
|
133
133
|
"""
|
|
134
|
-
When I run
|
|
135
|
-
Then the examples should all pass
|
|
136
|
-
|
|
137
|
-
Scenario: passing spec with rendering of Prototype helper update
|
|
138
|
-
Given a file named "spec/views/widgets/prototype_update.html.erb_spec.rb" with:
|
|
139
|
-
"""
|
|
140
|
-
require "spec_helper"
|
|
141
|
-
|
|
142
|
-
describe "render a Prototype helper update" do
|
|
143
|
-
it "hides the status indicator" do
|
|
144
|
-
|
|
145
|
-
render :update do |page|
|
|
146
|
-
page.hide 'status-indicator'
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
rendered.should contain("Element.hide(\"status-indicator\")")
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
"""
|
|
153
|
-
When I run "rspec spec/views"
|
|
134
|
+
When I run `rspec spec/views`
|
|
154
135
|
Then the examples should all pass
|
|
155
136
|
|
|
156
137
|
Scenario: spec with view that accesses helper_method helpers
|
|
@@ -177,9 +158,9 @@ Feature: view spec
|
|
|
177
158
|
|
|
178
159
|
it 'checks for admin access' do
|
|
179
160
|
render
|
|
180
|
-
rendered.should
|
|
161
|
+
rendered.should =~ /Secret admin area/
|
|
181
162
|
end
|
|
182
163
|
end
|
|
183
164
|
"""
|
|
184
|
-
When I run
|
|
165
|
+
When I run `rspec spec/views/secrets`
|
|
185
166
|
Then the examples should all pass
|
data/gemfiles/base.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module GemfileBase
|
|
2
|
+
def self.extended(host)
|
|
3
|
+
host.instance_eval do
|
|
4
|
+
source "http://rubygems.org"
|
|
5
|
+
|
|
6
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-rails].each do |lib|
|
|
7
|
+
library_path = File.expand_path("../../../#{lib}", __FILE__)
|
|
8
|
+
if File.exist?(library_path)
|
|
9
|
+
gem lib, :path => library_path
|
|
10
|
+
elsif ENV["CI"] || ENV["USE_GIT_REPOS"]
|
|
11
|
+
gem lib, :git => "git://github.com/rspec/#{lib}.git"
|
|
12
|
+
else
|
|
13
|
+
gem lib
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
18
|
+
gem "cucumber", "~> 0.10.2"
|
|
19
|
+
gem "aruba", "~> 0.3.6"
|
|
20
|
+
gem "growl", "1.0.3"
|
|
21
|
+
gem "ZenTest", "~> 4.4.2"
|
|
22
|
+
|
|
23
|
+
# gem "webrat", "0.7.3"
|
|
24
|
+
# gem "capybara", "~> 0.4"
|
|
25
|
+
# gem "capybara", "1.0.0.beta1"
|
|
26
|
+
|
|
27
|
+
unless ENV['CI']
|
|
28
|
+
gem "rcov", "0.9.9"
|
|
29
|
+
gem "relish", "0.2.0"
|
|
30
|
+
gem "guard-rspec", "0.1.9"
|
|
31
|
+
|
|
32
|
+
if RUBY_PLATFORM =~ /darwin/
|
|
33
|
+
gem "autotest-fsevent", "~> 0.2.4"
|
|
34
|
+
gem "autotest-growl", "~> 0.2.9"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
platforms :mri_18 do
|
|
38
|
+
gem 'ruby-debug'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
platforms :mri_19 do
|
|
42
|
+
gem 'linecache19', '0.5.11' # 0.5.12 cannot install on 1.9.1, and 0.5.11 appears to work with both 1.9.1 & 1.9.2
|
|
43
|
+
gem 'ruby-debug19'
|
|
44
|
+
gem 'ruby-debug-base19', RUBY_VERSION == '1.9.1' ? '0.11.23' : '~> 0.11.24'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
platforms :ruby_18, :ruby_19 do
|
|
48
|
+
gem "rb-fsevent", "~> 0.3.9"
|
|
49
|
+
gem "ruby-prof", "~> 0.9.2"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
platforms :jruby do
|
|
54
|
+
gem "jruby-openssl"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -65,6 +65,24 @@ module Rspec
|
|
|
65
65
|
"{'these' => 'params'}"
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
# support for namespaced-resources
|
|
69
|
+
def ns_file_name
|
|
70
|
+
if ARGV[0].match(/(\w+)\/(\w+)/)
|
|
71
|
+
"#{$1.underscore}_#{$2.singularize.underscore}"
|
|
72
|
+
else
|
|
73
|
+
file_name
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# support for namespaced-resources
|
|
78
|
+
def ns_table_name
|
|
79
|
+
if ARGV[0].match(/(\w+)\/(\w+)/)
|
|
80
|
+
"#{$1.underscore}/#{$2.tableize}"
|
|
81
|
+
else
|
|
82
|
+
table_name
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
68
86
|
# Returns the name of the mock. For example, if the file name is user,
|
|
69
87
|
# it returns mock_user.
|
|
70
88
|
#
|
|
@@ -81,9 +99,9 @@ module Rspec
|
|
|
81
99
|
if hash
|
|
82
100
|
method, and_return = hash.to_a.first
|
|
83
101
|
method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
|
|
84
|
-
"mock_#{
|
|
102
|
+
"mock_#{ns_file_name}(:#{method} => #{and_return})"
|
|
85
103
|
else
|
|
86
|
-
"mock_#{
|
|
104
|
+
"mock_#{ns_file_name}"
|
|
87
105
|
end
|
|
88
106
|
end
|
|
89
107
|
|
|
@@ -2,73 +2,96 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
|
4
4
|
# It demonstrates how one might use RSpec to specify the controller code that
|
|
5
|
-
# was generated by
|
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
|
6
|
+
#
|
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
|
9
|
+
# controller code, this generated spec may or may not pass.
|
|
10
|
+
#
|
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
|
14
|
+
#
|
|
15
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
|
19
|
+
# that an instance is receiving a specific message.
|
|
6
20
|
|
|
7
21
|
describe <%= controller_class_name %>Controller do
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
# This should return the minimal set of attributes required to create a valid
|
|
24
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
|
25
|
+
# update the return value of this method accordingly.
|
|
26
|
+
def valid_attributes
|
|
27
|
+
{}
|
|
11
28
|
end
|
|
12
29
|
|
|
13
30
|
<% unless options[:singleton] -%>
|
|
14
31
|
describe "GET index" do
|
|
15
32
|
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
|
16
|
-
<%=
|
|
33
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
17
34
|
get :index
|
|
18
|
-
assigns(:<%= table_name %>).should eq([<%=
|
|
35
|
+
assigns(:<%= table_name %>).should eq([<%= file_name %>])
|
|
19
36
|
end
|
|
20
37
|
end
|
|
21
38
|
|
|
22
39
|
<% end -%>
|
|
23
40
|
describe "GET show" do
|
|
24
|
-
it "assigns the requested <%=
|
|
25
|
-
<%=
|
|
26
|
-
get :show, :id =>
|
|
27
|
-
assigns(:<%=
|
|
41
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
42
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
43
|
+
get :show, :id => <%= file_name %>.id.to_s
|
|
44
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
28
45
|
end
|
|
29
46
|
end
|
|
30
47
|
|
|
31
48
|
describe "GET new" do
|
|
32
|
-
it "assigns a new <%=
|
|
33
|
-
<%= stub orm_class.build(class_name) %> { <%= mock_file_name %> }
|
|
49
|
+
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
34
50
|
get :new
|
|
35
|
-
assigns(:<%=
|
|
51
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
|
36
52
|
end
|
|
37
53
|
end
|
|
38
54
|
|
|
39
55
|
describe "GET edit" do
|
|
40
|
-
it "assigns the requested <%=
|
|
41
|
-
<%=
|
|
42
|
-
get :edit, :id =>
|
|
43
|
-
assigns(:<%=
|
|
56
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
57
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
58
|
+
get :edit, :id => <%= file_name %>.id.to_s
|
|
59
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
44
60
|
end
|
|
45
61
|
end
|
|
46
62
|
|
|
47
63
|
describe "POST create" do
|
|
48
64
|
describe "with valid params" do
|
|
49
|
-
it "
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
it "creates a new <%= class_name %>" do
|
|
66
|
+
expect {
|
|
67
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
|
68
|
+
}.to change(<%= class_name %>, :count).by(1)
|
|
53
69
|
end
|
|
54
70
|
|
|
55
|
-
it "
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
72
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
|
73
|
+
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
|
|
74
|
+
assigns(:<%= ns_file_name %>).should be_persisted
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "redirects to the created <%= ns_file_name %>" do
|
|
78
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
|
79
|
+
response.should redirect_to(<%= class_name %>.last)
|
|
59
80
|
end
|
|
60
81
|
end
|
|
61
82
|
|
|
62
83
|
describe "with invalid params" do
|
|
63
|
-
it "assigns a newly created but unsaved <%=
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
85
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
86
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
87
|
+
post :create, :<%= ns_file_name %> => {}
|
|
88
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
|
67
89
|
end
|
|
68
90
|
|
|
69
91
|
it "re-renders the 'new' template" do
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
93
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
94
|
+
post :create, :<%= ns_file_name %> => {}
|
|
72
95
|
response.should render_template("new")
|
|
73
96
|
end
|
|
74
97
|
end
|
|
@@ -76,50 +99,59 @@ describe <%= controller_class_name %>Controller do
|
|
|
76
99
|
|
|
77
100
|
describe "PUT update" do
|
|
78
101
|
describe "with valid params" do
|
|
79
|
-
it "updates the requested <%=
|
|
80
|
-
<%=
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
it "updates the requested <%= ns_file_name %>" do
|
|
103
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
104
|
+
# Assuming there are no other <%= table_name %> in the database, this
|
|
105
|
+
# specifies that the <%= class_name %> created on the previous line
|
|
106
|
+
# receives the :update_attributes message with whatever params are
|
|
107
|
+
# submitted in the request.
|
|
108
|
+
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
|
|
109
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
|
|
83
110
|
end
|
|
84
111
|
|
|
85
|
-
it "assigns the requested <%=
|
|
86
|
-
<%=
|
|
87
|
-
put :update, :id =>
|
|
88
|
-
assigns(:<%=
|
|
112
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
113
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
114
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
|
|
115
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
89
116
|
end
|
|
90
117
|
|
|
91
|
-
it "redirects to the <%=
|
|
92
|
-
<%=
|
|
93
|
-
put :update, :id =>
|
|
94
|
-
response.should redirect_to(<%=
|
|
118
|
+
it "redirects to the <%= ns_file_name %>" do
|
|
119
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
120
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
|
|
121
|
+
response.should redirect_to(<%= file_name %>)
|
|
95
122
|
end
|
|
96
123
|
end
|
|
97
124
|
|
|
98
125
|
describe "with invalid params" do
|
|
99
|
-
it "assigns the <%=
|
|
100
|
-
<%=
|
|
101
|
-
|
|
102
|
-
|
|
126
|
+
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
127
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
128
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
129
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
130
|
+
put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
|
|
131
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
103
132
|
end
|
|
104
133
|
|
|
105
134
|
it "re-renders the 'edit' template" do
|
|
106
|
-
<%=
|
|
107
|
-
|
|
135
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
136
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
137
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
138
|
+
put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
|
|
108
139
|
response.should render_template("edit")
|
|
109
140
|
end
|
|
110
141
|
end
|
|
111
142
|
end
|
|
112
143
|
|
|
113
144
|
describe "DELETE destroy" do
|
|
114
|
-
it "destroys the requested <%=
|
|
115
|
-
<%=
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
it "destroys the requested <%= ns_file_name %>" do
|
|
146
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
147
|
+
expect {
|
|
148
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
|
149
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
|
118
150
|
end
|
|
119
151
|
|
|
120
152
|
it "redirects to the <%= table_name %> list" do
|
|
121
|
-
<%=
|
|
122
|
-
delete :destroy, :id =>
|
|
153
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
154
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
|
123
155
|
response.should redirect_to(<%= index_helper %>_url)
|
|
124
156
|
end
|
|
125
157
|
end
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/edit.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
|
-
@<%=
|
|
6
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
|
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
|
8
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
|
9
9
|
<% end -%>
|
|
10
10
|
<%= output_attributes.empty? ? "" : " ))\n" -%>
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
it "renders the edit <%=
|
|
13
|
+
it "renders the edit <%= ns_file_name %> form" do
|
|
14
14
|
render
|
|
15
15
|
|
|
16
16
|
<% if webrat? -%>
|
|
17
|
-
rendered.should have_selector("form", :action => <%=
|
|
17
|
+
rendered.should have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
|
|
18
18
|
<% for attribute in output_attributes -%>
|
|
19
|
-
form.should have_selector("<%= attribute.input_type -%>#<%=
|
|
19
|
+
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
|
20
20
|
<% end -%>
|
|
21
21
|
end
|
|
22
22
|
<% else -%>
|
|
23
23
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
|
24
|
-
assert_select "form", :action => <%= index_helper %>_path(@<%=
|
|
24
|
+
assert_select "form", :action => <%= index_helper %>_path(@<%= ns_file_name %>), :method => "post" do
|
|
25
25
|
<% for attribute in output_attributes -%>
|
|
26
|
-
assert_select "<%= attribute.input_type -%>#<%=
|
|
26
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
|
|
27
27
|
<% end -%>
|
|
28
28
|
end
|
|
29
29
|
<% end -%>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
6
|
assign(:<%= table_name %>, [
|
|
7
7
|
<% [1,2].each_with_index do |id, model_index| -%>
|
|
@@ -16,7 +16,7 @@ describe "<%= table_name %>/index.html.<%= options[:template_engine] %>" do
|
|
|
16
16
|
])
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
it "renders a list of <%=
|
|
19
|
+
it "renders a list of <%= ns_table_name %>" do
|
|
20
20
|
render
|
|
21
21
|
<% for attribute in output_attributes -%>
|
|
22
22
|
<% if webrat? -%>
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/new.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
|
-
assign(:<%=
|
|
6
|
+
assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
|
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
|
8
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
|
9
9
|
<% end -%>
|
|
10
10
|
<%= !output_attributes.empty? ? " ).as_new_record)\n end" : " end" %>
|
|
11
11
|
|
|
12
|
-
it "renders new <%=
|
|
12
|
+
it "renders new <%= ns_file_name %> form" do
|
|
13
13
|
render
|
|
14
14
|
|
|
15
15
|
<% if webrat? -%>
|
|
16
16
|
rendered.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
|
|
17
17
|
<% for attribute in output_attributes -%>
|
|
18
|
-
form.should have_selector("<%= attribute.input_type -%>#<%=
|
|
18
|
+
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
|
19
19
|
<% end -%>
|
|
20
20
|
end
|
|
21
21
|
<% else -%>
|
|
22
22
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
|
23
23
|
assert_select "form", :action => <%= index_helper %>_path, :method => "post" do
|
|
24
24
|
<% for attribute in output_attributes -%>
|
|
25
|
-
assert_select "<%= attribute.input_type -%>#<%=
|
|
25
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
|
|
26
26
|
<% end -%>
|
|
27
27
|
end
|
|
28
28
|
<% end -%>
|