rspec-rails 4.0.0 → 6.1.2
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 +247 -53
- data/README.md +73 -61
- data/lib/generators/rspec/channel/channel_generator.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +5 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +6 -1
- data/lib/generators/rspec/feature/feature_generator.rb +1 -1
- data/lib/generators/rspec/generator/generator_generator.rb +3 -3
- data/lib/generators/rspec/generator/templates/generator_spec.rb +1 -2
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +19 -2
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +13 -8
- data/lib/generators/rspec/integration/integration_generator.rb +10 -3
- 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/mailbox/mailbox_generator.rb +1 -1
- data/lib/generators/rspec/mailer/mailer_generator.rb +5 -3
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +2 -2
- data/lib/generators/rspec/model/model_generator.rb +3 -3
- data/lib/generators/rspec/request/request_generator.rb +10 -3
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +8 -4
- 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 +25 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +8 -8
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +38 -18
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +14 -16
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +18 -1
- data/lib/rspec/rails/adapters.rb +11 -0
- data/lib/rspec/rails/configuration.rb +82 -18
- data/lib/rspec/rails/example/controller_example_group.rb +1 -0
- data/lib/rspec/rails/example/mailbox_example_group.rb +2 -2
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +8 -0
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/system_example_group.rb +63 -15
- data/lib/rspec/rails/example/view_example_group.rb +6 -5
- data/lib/rspec/rails/extensions/active_record/proxy.rb +4 -1
- data/lib/rspec/rails/feature_check.rb +6 -2
- data/lib/rspec/rails/file_fixture_support.rb +11 -10
- data/lib/rspec/rails/fixture_file_upload_support.rb +19 -14
- data/lib/rspec/rails/fixture_support.rb +49 -24
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +6 -3
- data/lib/rspec/rails/matchers/action_mailbox.rb +14 -5
- data/lib/rspec/rails/matchers/active_job.rb +32 -6
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +34 -5
- data/lib/rspec/rails/matchers/have_http_status.rb +5 -5
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +2 -2
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +1 -0
- data/lib/rspec/rails/vendor/capybara.rb +1 -3
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +0 -18
- data/lib/rspec/rails/view_rendering.rb +13 -11
- data/lib/rspec-rails.rb +13 -11
- data.tar.gz.sig +0 -0
- metadata +28 -27
- metadata.gz.sig +0 -0
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
@@ -16,18 +16,18 @@ module Rspec
|
|
16
16
|
return unless options[:request_specs]
|
17
17
|
|
18
18
|
template 'request_spec.rb',
|
19
|
-
|
19
|
+
target_path('requests', class_path, "#{file_name}_spec.rb")
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_controller_spec
|
23
23
|
return unless options[:controller_specs]
|
24
24
|
|
25
25
|
template 'controller_spec.rb',
|
26
|
-
|
26
|
+
target_path('controllers', class_path, "#{file_name}_controller_spec.rb")
|
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)
|
@@ -35,7 +35,7 @@ module Rspec
|
|
35
35
|
actions.each do |action|
|
36
36
|
@action = action
|
37
37
|
template 'view_spec.rb',
|
38
|
-
|
38
|
+
target_path('views', file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -44,7 +44,7 @@ module Rspec
|
|
44
44
|
return unless options[:routing_specs]
|
45
45
|
|
46
46
|
template 'routing_spec.rb',
|
47
|
-
|
47
|
+
target_path('routing', class_path, "#{file_name}_routing_spec.rb")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -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
|
@@ -10,7 +10,7 @@ module Rspec
|
|
10
10
|
def generate_feature_spec
|
11
11
|
return unless options[:feature_specs]
|
12
12
|
|
13
|
-
template template_name,
|
13
|
+
template template_name, target_path('features', class_path, filename)
|
14
14
|
end
|
15
15
|
|
16
16
|
def template_name
|
@@ -4,12 +4,12 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class GeneratorGenerator < Base
|
7
|
-
class_option :generator_specs, type: :boolean, default: true,
|
7
|
+
class_option :generator_specs, type: :boolean, default: true, desc: 'Generate generator specs'
|
8
8
|
|
9
9
|
def generate_generator_spec
|
10
10
|
return unless options[:generator_specs]
|
11
11
|
|
12
|
-
template template_name,
|
12
|
+
template template_name, target_path('generator', class_path, filename)
|
13
13
|
end
|
14
14
|
|
15
15
|
def template_name
|
@@ -17,7 +17,7 @@ module Rspec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def filename
|
20
|
-
"#{
|
20
|
+
"#{file_name}_generator_spec.rb"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -9,7 +9,7 @@ module Rspec
|
|
9
9
|
def generate_helper_spec
|
10
10
|
return unless options[:helper_specs]
|
11
11
|
|
12
|
-
template 'helper_spec.rb',
|
12
|
+
template 'helper_spec.rb', target_path('helpers', class_path, "#{file_name}_helper_spec.rb")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -12,6 +12,8 @@ Description:
|
|
12
12
|
Copy rspec files to your application.
|
13
13
|
DESC
|
14
14
|
|
15
|
+
class_option :default_path, type: :string, default: 'spec'
|
16
|
+
|
15
17
|
def self.source_root
|
16
18
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
17
19
|
end
|
@@ -20,12 +22,12 @@ DESC
|
|
20
22
|
Dir.mktmpdir do |dir|
|
21
23
|
generate_rspec_init dir
|
22
24
|
template File.join(dir, '.rspec'), '.rspec'
|
23
|
-
directory File.join(dir, 'spec'),
|
25
|
+
directory File.join(dir, 'spec'), default_path
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
def copy_rails_files
|
28
|
-
template 'spec/rails_helper.rb'
|
30
|
+
template 'spec/rails_helper.rb', "#{default_path}/rails_helper.rb"
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
@@ -41,6 +43,12 @@ DESC
|
|
41
43
|
|
42
44
|
replace_generator_command(spec_helper_path)
|
43
45
|
remove_warnings_configuration(spec_helper_path)
|
46
|
+
|
47
|
+
unless default_path == "spec"
|
48
|
+
dot_rspec_path = File.join(tmpdir, '.rspec')
|
49
|
+
|
50
|
+
append_default_path(dot_rspec_path)
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
def replace_generator_command(spec_helper_path)
|
@@ -58,6 +66,15 @@ DESC
|
|
58
66
|
'',
|
59
67
|
verbose: false
|
60
68
|
end
|
69
|
+
|
70
|
+
def append_default_path(dot_rspec_path)
|
71
|
+
append_to_file dot_rspec_path,
|
72
|
+
"--default-path #{default_path}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_path
|
76
|
+
options[:default_path]
|
77
|
+
end
|
61
78
|
end
|
62
79
|
end
|
63
80
|
end
|
@@ -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'
|
@@ -20,7 +20,7 @@ require 'rspec/rails'
|
|
20
20
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
21
|
# require only the support files necessary.
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }
|
24
24
|
|
25
25
|
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
26
26
|
# Checks for pending migrations and applies them before tests are run.
|
@@ -28,14 +28,19 @@ require 'rspec/rails'
|
|
28
28
|
begin
|
29
29
|
ActiveRecord::Migration.maintain_test_schema!
|
30
30
|
rescue ActiveRecord::PendingMigrationError => e
|
31
|
-
|
32
|
-
exit 1
|
31
|
+
abort e.to_s.strip
|
33
32
|
end
|
34
33
|
<% end -%>
|
35
34
|
RSpec.configure do |config|
|
36
35
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
37
36
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
38
|
-
|
37
|
+
<% if ::Rails::VERSION::STRING < "7.1.0" -%>
|
38
|
+
config.fixture_path = Rails.root.join('spec/fixtures')
|
39
|
+
<% else -%>
|
40
|
+
config.fixture_paths = [
|
41
|
+
Rails.root.join('spec/fixtures')
|
42
|
+
]
|
43
|
+
<% end -%>
|
39
44
|
|
40
45
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
41
46
|
# examples within a transaction, remove the following line or assign false
|
@@ -49,11 +54,11 @@ RSpec.configure do |config|
|
|
49
54
|
# Remove this line to enable support for ActiveRecord
|
50
55
|
config.use_active_record = false
|
51
56
|
|
52
|
-
# If you enable ActiveRecord support you should
|
57
|
+
# If you enable ActiveRecord support you should uncomment these lines,
|
53
58
|
# note if you'd prefer not to run each example within a transaction, you
|
54
59
|
# should set use_transactional_fixtures to false.
|
55
60
|
#
|
56
|
-
# config.fixture_path =
|
61
|
+
# config.fixture_path = Rails.root.join('spec/fixtures')
|
57
62
|
# config.use_transactional_fixtures = true
|
58
63
|
|
59
64
|
<% end -%>
|
@@ -69,7 +74,7 @@ RSpec.configure do |config|
|
|
69
74
|
# end
|
70
75
|
#
|
71
76
|
# The different available types are documented in the features, such as in
|
72
|
-
# https://
|
77
|
+
# https://rspec.info/features/6-0/rspec-rails
|
73
78
|
config.infer_spec_type_from_file_location!
|
74
79
|
|
75
80
|
# Filter lines from Rails gems in backtraces.
|
@@ -1,21 +1,28 @@
|
|
1
1
|
require 'generators/rspec'
|
2
|
+
require 'rspec/core/warnings'
|
2
3
|
|
3
4
|
module Rspec
|
4
5
|
module Generators
|
5
6
|
# @private
|
6
7
|
class IntegrationGenerator < Base
|
7
|
-
# Add a deprecation for this class, before rspec-rails 4, to use the
|
8
|
-
# `RequestGenerator` instead
|
9
8
|
class_option :request_specs,
|
10
9
|
type: :boolean,
|
11
10
|
default: true,
|
12
11
|
desc: "Generate request specs"
|
13
12
|
|
13
|
+
source_paths << File.expand_path('../request/templates', __dir__)
|
14
|
+
|
14
15
|
def generate_request_spec
|
15
16
|
return unless options[:request_specs]
|
16
17
|
|
18
|
+
RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/, ' ')
|
19
|
+
|The integration generator is deprecated
|
20
|
+
|and will be deleted in RSpec-Rails 7.
|
21
|
+
|Please use the request generator instead.
|
22
|
+
WARNING
|
23
|
+
|
17
24
|
template 'request_spec.rb',
|
18
|
-
|
25
|
+
target_path('requests', "#{name.underscore.pluralize}_spec.rb")
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -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', target_path('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 -%>
|
@@ -6,7 +6,7 @@ module Rspec
|
|
6
6
|
class MailboxGenerator < Base
|
7
7
|
def create_mailbox_spec
|
8
8
|
template('mailbox_spec.rb.erb',
|
9
|
-
|
9
|
+
target_path('mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
|
10
10
|
)
|
11
11
|
end
|
12
12
|
end
|
@@ -8,20 +8,22 @@ module Rspec
|
|
8
8
|
argument :actions, type: :array, default: [], banner: "method method"
|
9
9
|
|
10
10
|
def generate_mailer_spec
|
11
|
-
|
11
|
+
file_suffix = file_name.end_with?('mailer') ? 'spec.rb' : 'mailer_spec.rb'
|
12
|
+
template "mailer_spec.rb", target_path('mailers', class_path, [file_name, file_suffix].join('_'))
|
12
13
|
end
|
13
14
|
|
14
15
|
def generate_fixtures_files
|
15
16
|
actions.each do |action|
|
16
17
|
@action, @path = action, File.join(file_path, action)
|
17
|
-
template "fixture",
|
18
|
+
template "fixture", target_path("fixtures", @path)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def generate_preview_files
|
22
23
|
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
23
24
|
|
24
|
-
|
25
|
+
file_suffix = file_name.end_with?('mailer') ? 'preview.rb' : 'mailer_preview.rb'
|
26
|
+
template "preview.rb", target_path("mailers/previews", class_path, [file_name, file_suffix].join('_'))
|
25
27
|
end
|
26
28
|
end
|
27
29
|
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 %>)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
# Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>
|
3
|
-
class <%= class_name %>Preview < ActionMailer::Preview
|
3
|
+
class <%= class_name %><%= 'Mailer' unless class_name.end_with?('Mailer') %>Preview < ActionMailer::Preview
|
4
4
|
<% actions.each do |action| -%>
|
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
|
|
@@ -11,8 +11,8 @@ module Rspec
|
|
11
11
|
class_option :fixture, type: :boolean
|
12
12
|
|
13
13
|
def create_model_spec
|
14
|
-
template_file =
|
15
|
-
'
|
14
|
+
template_file = target_path(
|
15
|
+
'models',
|
16
16
|
class_path,
|
17
17
|
"#{file_name}_spec.rb"
|
18
18
|
)
|
@@ -24,7 +24,7 @@ module Rspec
|
|
24
24
|
def create_fixture_file
|
25
25
|
return unless missing_fixture_replacement?
|
26
26
|
|
27
|
-
template 'fixtures.yml',
|
27
|
+
template 'fixtures.yml', target_path('fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -1,10 +1,17 @@
|
|
1
|
-
require 'generators/rspec
|
1
|
+
require 'generators/rspec'
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
|
-
class RequestGenerator <
|
7
|
-
|
6
|
+
class RequestGenerator < Base
|
7
|
+
class_option :request_specs, type: :boolean, default: true, desc: 'Generate request specs'
|
8
|
+
|
9
|
+
def generate_request_spec
|
10
|
+
return unless options[:request_specs]
|
11
|
+
|
12
|
+
template 'request_spec.rb',
|
13
|
+
target_path('requests', "#{name.underscore.pluralize}_spec.rb")
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -58,8 +58,8 @@ module Rspec
|
|
58
58
|
def generate_routing_spec
|
59
59
|
return unless options[:routing_specs]
|
60
60
|
|
61
|
-
template_file =
|
62
|
-
'
|
61
|
+
template_file = target_path(
|
62
|
+
'routing',
|
63
63
|
controller_class_path,
|
64
64
|
"#{controller_file_name}_routing_spec.rb"
|
65
65
|
)
|
@@ -72,7 +72,7 @@ module Rspec
|
|
72
72
|
|
73
73
|
def copy_view(view)
|
74
74
|
template "#{view}_spec.rb",
|
75
|
-
|
75
|
+
target_path("views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
76
76
|
end
|
77
77
|
|
78
78
|
# support for namespaced-resources
|
@@ -121,12 +121,16 @@ module Rspec
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def template_file(folder:, suffix: '')
|
124
|
-
|
124
|
+
target_path(folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
|
125
125
|
end
|
126
126
|
|
127
127
|
def banner
|
128
128
|
self.class.banner
|
129
129
|
end
|
130
|
+
|
131
|
+
def show_helper(resource_name = file_name)
|
132
|
+
"#{singular_route_name}_url(#{resource_name})"
|
133
|
+
end
|
130
134
|
end
|
131
135
|
end
|
132
136
|
end
|
@@ -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 %>: new_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
|