rspec-rails 4.0.1 → 5.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +91 -2
- data/README.md +41 -32
- data/lib/generators/rspec/controller/controller_generator.rb +2 -2
- data/lib/generators/rspec/controller/templates/request_spec.rb +6 -1
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +1 -1
- data/lib/generators/rspec/job/job_generator.rb +2 -1
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +4 -0
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -13
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +20 -20
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -4
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -4
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +23 -18
- data/lib/generators/rspec/system/system_generator.rb +14 -16
- data/lib/rspec/rails/configuration.rb +40 -6
- data/lib/rspec/rails/example/controller_example_group.rb +1 -0
- data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/system_example_group.rb +3 -2
- data/lib/rspec/rails/extensions/active_record/proxy.rb +4 -1
- data/lib/rspec/rails/file_fixture_support.rb +9 -11
- data/lib/rspec/rails/fixture_file_upload_support.rb +32 -16
- data/lib/rspec/rails/fixture_support.rb +9 -12
- data/lib/rspec/rails/matchers/action_mailbox.rb +14 -5
- data/lib/rspec/rails/matchers/active_job.rb +23 -1
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +30 -2
- data/lib/rspec/rails/matchers/have_http_status.rb +4 -4
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec-rails.rb +5 -7
- data.tar.gz.sig +0 -0
- metadata +39 -27
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9911ecc326fa2e641d1d5236121f9b93c9ee47d06c85824eb65c619e4ca81c1e
|
4
|
+
data.tar.gz: 0515b3c5ace9cd0b61ccf7824c2d026c1695e7e5ebe4f2c1c50bea64af1dc1b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d76e8a54ff22a9284826050b6a1bbb09d1fb46f395d980e729051ea60ce0cd2441cc926db3d6818e7fb314d57ede64e2d42373ebd887b77a522306e4733688
|
7
|
+
data.tar.gz: decce0771196535865fb7facd775edf339f79b7463cd5c53c18ad30aca4d61db6f00c2123307709c6a89bce5aec4338f7a16ab3db1a95677997fb6e8eaae3d42
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,94 @@
|
|
1
1
|
### Development
|
2
|
-
[Full Changelog](https://github.com/rspec/rspec-rails/compare/
|
2
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.1.0...5-1-maintenance)
|
3
|
+
|
4
|
+
### 5.1.0 / 2022-01-26
|
5
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.3...v5.1.0)
|
6
|
+
|
7
|
+
Enhancements:
|
8
|
+
|
9
|
+
* Make the API request scaffold template more consistent and compatible with
|
10
|
+
Rails 6.1. (Naoto Hamada, #2484)
|
11
|
+
* Change the scaffold `rails_helper.rb` template to use `require_relative`.
|
12
|
+
(Jon Dufresne, #2528)
|
13
|
+
|
14
|
+
### 5.0.3 / 2022-01-26
|
15
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.2...v5.0.3)
|
16
|
+
|
17
|
+
Bug Fixes:
|
18
|
+
|
19
|
+
* Properly name params in controller and request spec templates when
|
20
|
+
using the `--model-name` parameter. (@kenzo-tanaka, #2534)
|
21
|
+
* Fix support for `have_enqueued_mail` on Ruby 3.1 with Rails 6.1.
|
22
|
+
(Fabio Napoleoni, Mikael Henriksson, Phil Pirozhkov, Jon Rowe, #2566)
|
23
|
+
|
24
|
+
### 5.0.2 / 2021-08-14
|
25
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.1...v5.0.2)
|
26
|
+
|
27
|
+
Bug Fixes:
|
28
|
+
|
29
|
+
* Prevent generated job specs from duplicating `_job` in filenames.
|
30
|
+
(Nick Flückiger, #2496)
|
31
|
+
* Fix `ActiveRecord::TestFixture#uses_transaction` by using example description
|
32
|
+
to replace example name rather than example in our monkey patched
|
33
|
+
`run_in_transaction?` method. (Stan Lo, #2495)
|
34
|
+
* Prevent keyword arguments being lost when methods are invoked dynamically
|
35
|
+
in controller specs. (Josh Cheek, #2509, #2514)
|
36
|
+
|
37
|
+
### 5.0.1 / 2021-03-18
|
38
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.0...v5.0.1)
|
39
|
+
|
40
|
+
Bug Fixes:
|
41
|
+
|
42
|
+
* Limit multibyte example descriptions when used in system tests for #method_name
|
43
|
+
which ends up as screenshot names etc. (@y-yagi, #2405, #2487)
|
44
|
+
|
45
|
+
### 5.0.0 / 2021-03-09
|
46
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.1...v5.0.0)
|
47
|
+
|
48
|
+
Enhancements:
|
49
|
+
|
50
|
+
* Support new #file_fixture_path and new fixture test support code. (Jon Rowe, #2398)
|
51
|
+
* Support for Rails 6.1. (Benoit Tigeot, Jon Rowe, Phil Pirozhkov, and more #2398)
|
52
|
+
|
53
|
+
Breaking Changes:
|
54
|
+
|
55
|
+
* Drop support for Rails below 5.2.
|
56
|
+
|
57
|
+
### 4.1.1 / 2021-03-09
|
58
|
+
|
59
|
+
Bug Fixes:
|
60
|
+
|
61
|
+
* Remove generated specs when destroying a generated controller.
|
62
|
+
(@Naokimi, #2475)
|
63
|
+
|
64
|
+
### 4.1.0 / 2021-03-06
|
65
|
+
|
66
|
+
Enhancements:
|
67
|
+
|
68
|
+
* Issue a warning when using job matchers with `#at` mis-match on `usec` precision.
|
69
|
+
(Jon Rowe, #2350)
|
70
|
+
* Generated request specs now have a bare `_spec` suffix instead of `request_spec`.
|
71
|
+
(Eloy Espinaco, Luka Lüdicke, #2355, #2356, #2378)
|
72
|
+
* Generated scaffold now includes engine route helpers when inside a mountable engine.
|
73
|
+
(Andrew W. Lee, #2372)
|
74
|
+
* Improve request spec "controller" scafold when no action is specified.
|
75
|
+
(Thomas Hareau, #2399)
|
76
|
+
* Introduce testing snippets concept (Phil Pirozhkov, Benoit Tigeot, #2423)
|
77
|
+
* Prevent collisions with `let(:name)` for Rails 6.1 and `let(:method_name)` on older
|
78
|
+
Rails. (Benoit Tigeot, #2461)
|
79
|
+
|
80
|
+
### 4.0.2 / 2020-12-26
|
81
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.1...v4.0.2)
|
82
|
+
|
83
|
+
Bug Fixes:
|
84
|
+
|
85
|
+
* Indent all extra failure lines output from system specs. (Alex Robbin, #2321)
|
86
|
+
* Generated request spec for update now uses the correct let. (Paul Hanyzewski, #2344)
|
87
|
+
* Return `true`/`false` from predicate methods in config rather than raw values.
|
88
|
+
(Phil Pirozhkov, Jon Rowe, #2353, #2354)
|
89
|
+
* Remove old #fixture_path feature detection code which broke under newer Rails.
|
90
|
+
(Koen Punt, Jon Rowe, #2370)
|
91
|
+
* Fix an error when `use_active_record` is `false` (Phil Pirozhkov, #2423)
|
3
92
|
|
4
93
|
### 4.0.1 / 2020-05-16
|
5
94
|
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0...v4.0.1)
|
@@ -37,7 +126,7 @@ Enhancements:
|
|
37
126
|
generating a controller (Luka Lüdicke, #2222)
|
38
127
|
* Allow `ActiveJob` matchers `#on_queue` modifier to take symbolic queue names. (Nils Sommer, #2283)
|
39
128
|
* The scaffold generator now generates request specs in preference to controller specs.
|
40
|
-
(Luka
|
129
|
+
(Luka Lüdicke, #2288)
|
41
130
|
* Add configuration option to disable ActiveRecord. (Jon Rowe, Phil Pirozhkov, Hermann Mayer, #2266)
|
42
131
|
* Set `ActionDispatch::SystemTesting::Server.silence_puma = true` when running system specs.
|
43
132
|
(ta1kt0me, Benoit Tigeot, #2289)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# rspec-rails [![
|
1
|
+
# rspec-rails [![Code Climate][]][code-climate] [![Gem Version][]][gem-version]
|
2
2
|
|
3
3
|
`rspec-rails` brings the [RSpec][] testing framework to [Ruby on Rails][]
|
4
4
|
as a drop-in alternative to its default testing framework, Minitest.
|
@@ -8,10 +8,13 @@ They’re also specifications (or _specs,_ for short):
|
|
8
8
|
detailed explanations of how the application is supposed to behave,
|
9
9
|
expressed in plain English.
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
According to [RSpec Rails new versioning strategy][] use:
|
12
|
+
* **[`rspec-rails` 5.x][]** for Rails 6.x.
|
13
|
+
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
|
14
|
+
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
15
|
+
* **[`rspec-rails` 1.x][]** for Rails 2.x.
|
13
16
|
|
14
|
-
[Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=
|
17
|
+
[Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=main
|
15
18
|
[travis-ci]: https://travis-ci.org/rspec/rspec-rails
|
16
19
|
[Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
|
17
20
|
[code-climate]: https://codeclimate.com/github/rspec/rspec-rails
|
@@ -21,23 +24,29 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
|
|
21
24
|
[Ruby on Rails]: https://rubyonrails.org/
|
22
25
|
[`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
|
23
26
|
[`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
|
27
|
+
[`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
|
28
|
+
[`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-0-maintenance
|
29
|
+
[RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
|
24
30
|
|
25
31
|
## Installation
|
26
32
|
|
33
|
+
**IMPORTANT** This README / branch refers to the current development build.
|
34
|
+
See the [`5-0-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/5-0-maintenance) if you want or require the latest stable release.
|
35
|
+
|
27
36
|
1. Add `rspec-rails` to **both** the `:development` and `:test` groups
|
28
37
|
of your app’s `Gemfile`:
|
29
38
|
|
30
39
|
```ruby
|
31
|
-
# Run against
|
40
|
+
# Run against this stable release
|
32
41
|
group :development, :test do
|
33
|
-
gem 'rspec-rails', '~>
|
42
|
+
gem 'rspec-rails', '~> 5.0.0'
|
34
43
|
end
|
35
44
|
|
36
|
-
# Or, run against the
|
37
|
-
# (requires
|
45
|
+
# Or, run against the main branch
|
46
|
+
# (requires main-branch versions of all related RSpec libraries)
|
38
47
|
group :development, :test do
|
39
48
|
%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
|
40
|
-
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: '
|
49
|
+
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
|
41
50
|
end
|
42
51
|
end
|
43
52
|
```
|
@@ -184,17 +193,17 @@ In addition to [the matchers that come standard in RSpec][],
|
|
184
193
|
here are some extras that make it easier
|
185
194
|
to test the various parts of a Rails system:
|
186
195
|
|
187
|
-
| RSpec matcher | Delegates to
|
188
|
-
| ------------------------ |
|
189
|
-
| [`be_a_new`][] |
|
190
|
-
| [`render_template`][] | `assert_template`
|
191
|
-
| [`redirect_to`][] | `assert_redirect`
|
192
|
-
| [`route_to`] | `
|
193
|
-
| [`be_routable`] |
|
194
|
-
| [`have_http_status`][] |
|
195
|
-
| [`match_array`][] |
|
196
|
-
| [`have_been_enqueued`][] |
|
197
|
-
| [`have_enqueued_job`][] |
|
196
|
+
| RSpec matcher | Delegates to | Available in | Notes |
|
197
|
+
| ------------------------ | ------------------- | ------------------------------- | -------------------------------------------------------- |
|
198
|
+
| [`be_a_new`][] | | all | primarily intended for controller specs |
|
199
|
+
| [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
|
200
|
+
| [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
|
201
|
+
| [`route_to`] | `assert_recognizes` | routing / controller | use with `expect(...).to route_to` |
|
202
|
+
| [`be_routable`] | | routing / controller | use with `expect(...).not_to be_routable` |
|
203
|
+
| [`have_http_status`][] | | request / controller / feature | |
|
204
|
+
| [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
|
205
|
+
| [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
|
206
|
+
| [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
|
198
207
|
|
199
208
|
Follow the links above for examples of how each matcher is used.
|
200
209
|
|
@@ -224,18 +233,18 @@ Each one inherits from one of Rails’ built-in `TestCase` classes,
|
|
224
233
|
meaning the helper methods provided by default in Rails tests
|
225
234
|
are available in RSpec, as well.
|
226
235
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
236
|
+
| Spec type | Corresponding Rails test class |
|
237
|
+
| -------------- | -------------------------------- |
|
238
|
+
| [model][] | |
|
239
|
+
| [controller][] | [`ActionController::TestCase`][] |
|
240
|
+
| [mailer][] | `ActionMailer::TestCase` |
|
241
|
+
| [job][] | |
|
242
|
+
| [view][] | `ActionView::TestCase` |
|
243
|
+
| [routing][] | |
|
244
|
+
| [helper][] | `ActionView::TestCase` |
|
245
|
+
| [request][] | [`ActionDispatch::IntegrationTest`][] |
|
246
|
+
| [feature][] | |
|
247
|
+
| [system][] | [`ActionDispatch::SystemTestCase`][] |
|
239
248
|
|
240
249
|
Follow the links above to see examples of each spec type,
|
241
250
|
or for official Rails API documentation on the given `TestCase` class.
|
@@ -16,7 +16,7 @@ module Rspec
|
|
16
16
|
return unless options[:request_specs]
|
17
17
|
|
18
18
|
template 'request_spec.rb',
|
19
|
-
File.join('spec/requests', class_path, "#{file_name}
|
19
|
+
File.join('spec/requests', class_path, "#{file_name}_spec.rb")
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_controller_spec
|
@@ -27,7 +27,7 @@ module Rspec
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def generate_view_specs
|
30
|
-
return if actions.empty?
|
30
|
+
return if actions.empty? && behavior == :invoke
|
31
31
|
return unless options[:view_specs] && options[:template_engine]
|
32
32
|
|
33
33
|
empty_directory File.join("spec", "views", file_path)
|
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
-
<% namespaced_path = regular_class_path.join('/')
|
4
|
+
<% namespaced_path = regular_class_path.join('/') -%>
|
5
|
+
<% if actions.empty? -%>
|
6
|
+
describe "GET /index" do
|
7
|
+
pending "add some examples (or delete) #{__FILE__}"
|
8
|
+
end
|
9
|
+
<% end -%>
|
5
10
|
<% for action in actions -%>
|
6
11
|
describe "GET /<%= action %>" do
|
7
12
|
it "returns http success" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
2
|
require 'spec_helper'
|
3
3
|
ENV['RAILS_ENV'] ||= 'test'
|
4
|
-
|
4
|
+
require_relative '../config/environment'
|
5
5
|
# Prevent database truncation if the environment is production
|
6
6
|
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
7
7
|
require 'rspec/rails'
|
@@ -5,7 +5,8 @@ module Rspec
|
|
5
5
|
# @private
|
6
6
|
class JobGenerator < Base
|
7
7
|
def create_job_spec
|
8
|
-
|
8
|
+
file_suffix = file_name.end_with?('job') ? 'spec.rb' : 'job_spec.rb'
|
9
|
+
template 'job_spec.rb.erb', File.join('spec/jobs', class_path, [file_name, file_suffix].join('_'))
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%= class_name
|
4
|
+
RSpec.describe <%= class_name %><%= "Job" unless class_name.end_with?("Job")%>, <%= type_metatag(:job) %> do
|
5
5
|
pending "add some examples to (or delete) #{__FILE__}"
|
6
6
|
end
|
7
7
|
<% end -%>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "rails_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%=
|
4
|
+
RSpec.describe <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>, <%= type_metatag(:mailer) %> do
|
5
5
|
<% for action in actions -%>
|
6
6
|
describe "<%= action %>" do
|
7
|
-
let(:mail) { <%=
|
7
|
+
let(:mail) { <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %> }
|
8
8
|
|
9
9
|
it "renders the headers" do
|
10
10
|
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
|
@@ -5,7 +5,7 @@ class <%= class_name %>Preview < ActionMailer::Preview
|
|
5
5
|
|
6
6
|
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>
|
7
7
|
def <%= action %>
|
8
|
-
<%=
|
8
|
+
<%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
|
9
9
|
end
|
10
10
|
<% end -%>
|
11
11
|
|
@@ -64,21 +64,21 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
64
64
|
context "with valid params" do
|
65
65
|
it "creates a new <%= class_name %>" do
|
66
66
|
expect {
|
67
|
-
post :create, params: {<%=
|
67
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
68
68
|
}.to change(<%= class_name %>, :count).by(1)
|
69
69
|
end
|
70
70
|
|
71
|
-
it "renders a JSON response with the new <%=
|
72
|
-
post :create, params: {<%=
|
71
|
+
it "renders a JSON response with the new <%= singular_table_name %>" do
|
72
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
73
73
|
expect(response).to have_http_status(:created)
|
74
74
|
expect(response.content_type).to eq('application/json')
|
75
|
-
expect(response.location).to eq(<%=
|
75
|
+
expect(response.location).to eq(<%= singular_table_name %>_url(<%= class_name %>.last))
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
context "with invalid params" do
|
80
|
-
it "renders a JSON response with errors for the new <%=
|
81
|
-
post :create, params: {<%=
|
80
|
+
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
|
81
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
82
82
|
expect(response).to have_http_status(:unprocessable_entity)
|
83
83
|
expect(response.content_type).to eq('application/json')
|
84
84
|
end
|
@@ -91,25 +91,25 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
91
91
|
skip("Add a hash of attributes valid for your model")
|
92
92
|
}
|
93
93
|
|
94
|
-
it "updates the requested <%=
|
94
|
+
it "updates the requested <%= singular_table_name %>" do
|
95
95
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
96
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
97
97
|
<%= file_name %>.reload
|
98
98
|
skip("Add assertions for updated state")
|
99
99
|
end
|
100
100
|
|
101
|
-
it "renders a JSON response with the <%=
|
101
|
+
it "renders a JSON response with the <%= singular_table_name %>" do
|
102
102
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
103
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
103
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: valid_attributes}, session: valid_session
|
104
104
|
expect(response).to have_http_status(:ok)
|
105
105
|
expect(response.content_type).to eq('application/json')
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
context "with invalid params" do
|
110
|
-
it "renders a JSON response with errors for the <%=
|
110
|
+
it "renders a JSON response with errors for the <%= singular_table_name %>" do
|
111
111
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
112
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
112
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
113
113
|
expect(response).to have_http_status(:unprocessable_entity)
|
114
114
|
expect(response.content_type).to eq('application/json')
|
115
115
|
end
|
@@ -117,7 +117,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "DELETE #destroy" do
|
120
|
-
it "destroys the requested <%=
|
120
|
+
it "destroys the requested <%= singular_table_name %>" do
|
121
121
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
122
122
|
expect {
|
123
123
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
@@ -46,7 +46,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
46
46
|
describe "GET /show" do
|
47
47
|
it "renders a successful response" do
|
48
48
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
49
|
-
get <%= show_helper
|
49
|
+
get <%= show_helper %>, as: :json
|
50
50
|
expect(response).to be_successful
|
51
51
|
end
|
52
52
|
end
|
@@ -56,13 +56,13 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
56
56
|
it "creates a new <%= class_name %>" do
|
57
57
|
expect {
|
58
58
|
post <%= index_helper %>_url,
|
59
|
-
params: { <%=
|
59
|
+
params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
|
60
60
|
}.to change(<%= class_name %>, :count).by(1)
|
61
61
|
end
|
62
62
|
|
63
|
-
it "renders a JSON response with the new <%=
|
63
|
+
it "renders a JSON response with the new <%= singular_table_name %>" do
|
64
64
|
post <%= index_helper %>_url,
|
65
|
-
params: { <%=
|
65
|
+
params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
|
66
66
|
expect(response).to have_http_status(:created)
|
67
67
|
expect(response.content_type).to match(a_string_including("application/json"))
|
68
68
|
end
|
@@ -72,15 +72,15 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
72
72
|
it "does not create a new <%= class_name %>" do
|
73
73
|
expect {
|
74
74
|
post <%= index_helper %>_url,
|
75
|
-
params: { <%=
|
75
|
+
params: { <%= singular_table_name %>: invalid_attributes }, as: :json
|
76
76
|
}.to change(<%= class_name %>, :count).by(0)
|
77
77
|
end
|
78
78
|
|
79
|
-
it "renders a JSON response with errors for the new <%=
|
79
|
+
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
|
80
80
|
post <%= index_helper %>_url,
|
81
|
-
params: { <%=
|
81
|
+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
82
82
|
expect(response).to have_http_status(:unprocessable_entity)
|
83
|
-
expect(response.content_type).to
|
83
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -91,39 +91,39 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
91
91
|
skip("Add a hash of attributes valid for your model")
|
92
92
|
}
|
93
93
|
|
94
|
-
it "updates the requested <%=
|
94
|
+
it "updates the requested <%= singular_table_name %>" do
|
95
95
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
-
patch <%= show_helper
|
97
|
-
params: { <%= singular_table_name %>:
|
96
|
+
patch <%= show_helper %>,
|
97
|
+
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
|
98
98
|
<%= file_name %>.reload
|
99
99
|
skip("Add assertions for updated state")
|
100
100
|
end
|
101
101
|
|
102
|
-
it "renders a JSON response with the <%=
|
102
|
+
it "renders a JSON response with the <%= singular_table_name %>" do
|
103
103
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
104
|
-
patch <%= show_helper
|
105
|
-
params: { <%= singular_table_name %>:
|
104
|
+
patch <%= show_helper %>,
|
105
|
+
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
|
106
106
|
expect(response).to have_http_status(:ok)
|
107
|
-
expect(response.content_type).to
|
107
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
context "with invalid parameters" do
|
112
|
-
it "renders a JSON response with errors for the <%=
|
112
|
+
it "renders a JSON response with errors for the <%= singular_table_name %>" do
|
113
113
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
114
|
-
patch <%= show_helper
|
114
|
+
patch <%= show_helper %>,
|
115
115
|
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
116
116
|
expect(response).to have_http_status(:unprocessable_entity)
|
117
|
-
expect(response.content_type).to
|
117
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
describe "DELETE /destroy" do
|
123
|
-
it "destroys the requested <%=
|
123
|
+
it "destroys the requested <%= singular_table_name %>" do
|
124
124
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
125
|
expect {
|
126
|
-
delete <%= show_helper
|
126
|
+
delete <%= show_helper %>, headers: valid_headers, as: :json
|
127
127
|
}.to change(<%= class_name %>, :count).by(-1)
|
128
128
|
end
|
129
129
|
end
|