Skip to content

Commit

Permalink
RSpec - User Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
BaoKhanh99 committed Apr 5, 2022
1 parent e56143c commit e281bc1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
File renamed without changes.
25 changes: 25 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "rails_helper"
include SessionsHelper

RSpec.describe UsersController, type: :controller do
describe "GET #show" do
let!(:user) { create(:user)}

context "when user logged in" do
before do
log_in user
get :show, params: { id: user.id }
end
it "render show template" do
expect(response).to render_template(:show)
end
end

context "when user not logged in" do
it "redirect to login template" do
get :show, params: { id: user.id }
expect(response).to redirect_to login_path
end
end
end
end
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?

require "rspec/rails"
require "support/factory_bot"

Dir[Rails.root.join("spec", "support", "**", "*.rb")].each { |f| require f }

begin
ActiveRecord::Migration.maintain_test_schema!
Expand Down

0 comments on commit e281bc1

Please sign in to comment.