Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
393 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This file is copied to spec/ when you run 'rails generate rspec:install' | ||
require 'spec_helper' | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require_relative '../config/environment' | ||
# Prevent database truncation if the environment is production | ||
abort("The Rails environment is running in production mode!") if Rails.env.production? | ||
require 'rspec/rails' | ||
# Add additional requires below this line. Rails is not loaded until this point! | ||
|
||
# Requires supporting ruby files with custom matchers and macros, etc, in | ||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are | ||
# run as spec files by default. This means that files in spec/support that end | ||
# in _spec.rb will both be required and run as specs, causing the specs to be | ||
# run twice. It is recommended that you do not name files matching this glob to | ||
# end with _spec.rb. You can configure this pattern with the --pattern | ||
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. | ||
# | ||
# The following line is provided for convenience purposes. It has the downside | ||
# of increasing the boot-up time by auto-requiring all files in the support | ||
# directory. Alternatively, in the individual `*_spec.rb` files, manually | ||
# require only the support files necessary. | ||
# | ||
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } | ||
|
||
RSpec.configure do |config| | ||
# Remove this line to enable support for ActiveRecord | ||
config.use_active_record = false | ||
|
||
# If you enable ActiveRecord support you should unncomment these lines, | ||
# note if you'd prefer not to run each example within a transaction, you | ||
# should set use_transactional_fixtures to false. | ||
# | ||
# config.fixture_path = "#{::Rails.root}/spec/fixtures" | ||
# config.use_transactional_fixtures = true | ||
|
||
# RSpec Rails can automatically mix in different behaviours to your tests | ||
# based on their file location, for example enabling you to call `get` and | ||
# `post` in specs under `spec/controllers`. | ||
# | ||
# You can disable this behaviour by removing the line below, and instead | ||
# explicitly tag your specs with their type, e.g.: | ||
# | ||
# RSpec.describe UsersController, type: :controller do | ||
# # ... | ||
# end | ||
# | ||
# The different available types are documented in the features, such as in | ||
# https://relishapp.com/rspec/rspec-rails/docs | ||
config.infer_spec_type_from_file_location! | ||
|
||
# Filter lines from Rails gems in backtraces. | ||
config.filter_rails_from_backtrace! | ||
# arbitrary gems may also be filtered via: | ||
# config.filter_gems_from_backtrace("gem name") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
require 'rails_helper' | ||
|
||
# This spec was generated by rspec-rails when you ran the scaffold generator. | ||
# It demonstrates how one might use RSpec to test the controller code that | ||
# was generated by Rails when you ran the scaffold generator. | ||
# | ||
# It assumes that the implementation code is generated by the rails scaffold | ||
# generator. If you are using any extension libraries to generate different | ||
# controller code, this generated spec may or may not pass. | ||
# | ||
# It only uses APIs available in rails and/or rspec-rails. There are a number | ||
# of tools you can use to make these specs even more expressive, but we're | ||
# sticking to rails and rspec-rails APIs to keep things simple and stable. | ||
|
||
RSpec.describe "/users", type: :request do | ||
|
||
# This should return the minimal set of attributes required to create a valid | ||
# User. As you add validations to User, be sure to | ||
# adjust the attributes here as well. | ||
let(:valid_attributes) { | ||
skip("Add a hash of attributes valid for your model") | ||
} | ||
|
||
let(:invalid_attributes) { | ||
skip("Add a hash of attributes invalid for your model") | ||
} | ||
|
||
describe "GET /index" do | ||
it "renders a successful response" do | ||
User.create! valid_attributes | ||
get users_url | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET /show" do | ||
it "renders a successful response" do | ||
user = User.create! valid_attributes | ||
get user_url(user) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET /new" do | ||
it "renders a successful response" do | ||
get new_user_url | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET /edit" do | ||
it "renders a successful response" do | ||
user = User.create! valid_attributes | ||
get edit_user_url(user) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "POST /create" do | ||
context "with valid parameters" do | ||
it "creates a new User" do | ||
expect { | ||
post users_url, params: { user: valid_attributes } | ||
}.to change(User, :count).by(1) | ||
end | ||
|
||
it "redirects to the created user" do | ||
post users_url, params: { user: valid_attributes } | ||
expect(response).to redirect_to(user_url(User.last)) | ||
end | ||
end | ||
|
||
context "with invalid parameters" do | ||
it "does not create a new User" do | ||
expect { | ||
post users_url, params: { user: invalid_attributes } | ||
}.to change(User, :count).by(0) | ||
end | ||
|
||
it "renders a successful response (i.e. to display the 'new' template)" do | ||
post users_url, params: { user: invalid_attributes } | ||
expect(response).to be_successful | ||
end | ||
end | ||
end | ||
|
||
describe "PATCH /update" do | ||
context "with valid parameters" do | ||
let(:new_attributes) { | ||
skip("Add a hash of attributes valid for your model") | ||
} | ||
|
||
it "updates the requested user" do | ||
user = User.create! valid_attributes | ||
patch user_url(user), params: { user: new_attributes } | ||
user.reload | ||
skip("Add assertions for updated state") | ||
end | ||
|
||
it "redirects to the user" do | ||
user = User.create! valid_attributes | ||
patch user_url(user), params: { user: new_attributes } | ||
user.reload | ||
expect(response).to redirect_to(user_url(user)) | ||
end | ||
end | ||
|
||
context "with invalid parameters" do | ||
it "renders a successful response (i.e. to display the 'edit' template)" do | ||
user = User.create! valid_attributes | ||
patch user_url(user), params: { user: invalid_attributes } | ||
expect(response).to be_successful | ||
end | ||
end | ||
end | ||
|
||
describe "DELETE /destroy" do | ||
it "destroys the requested user" do | ||
user = User.create! valid_attributes | ||
expect { | ||
delete user_url(user) | ||
}.to change(User, :count).by(-1) | ||
end | ||
|
||
it "redirects to the users list" do | ||
user = User.create! valid_attributes | ||
delete user_url(user) | ||
expect(response).to redirect_to(users_url) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe UsersController, type: :routing do | ||
describe "routing" do | ||
it "routes to #index" do | ||
expect(get: "/users").to route_to("users#index") | ||
end | ||
|
||
it "routes to #new" do | ||
expect(get: "/users/new").to route_to("users#new") | ||
end | ||
|
||
it "routes to #show" do | ||
expect(get: "/users/1").to route_to("users#show", id: "1") | ||
end | ||
|
||
it "routes to #edit" do | ||
expect(get: "/users/1/edit").to route_to("users#edit", id: "1") | ||
end | ||
|
||
|
||
it "routes to #create" do | ||
expect(post: "/users").to route_to("users#create") | ||
end | ||
|
||
it "routes to #update via PUT" do | ||
expect(put: "/users/1").to route_to("users#update", id: "1") | ||
end | ||
|
||
it "routes to #update via PATCH" do | ||
expect(patch: "/users/1").to route_to("users#update", id: "1") | ||
end | ||
|
||
it "routes to #destroy" do | ||
expect(delete: "/users/1").to route_to("users#destroy", id: "1") | ||
end | ||
end | ||
end |
Oops, something went wrong.