-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from binhpt-1239/test_rspec
Rspec controller static_pages and bets
- Loading branch information
Showing
9 changed files
with
103 additions
and
4 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
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
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,48 @@ | ||
require "rails_helper" | ||
include SessionsHelper | ||
|
||
RSpec.describe BetsController, type: :controller do | ||
describe "GET index" do | ||
let!(:user){FactoryBot.create :user} | ||
let!(:match){FactoryBot.create :soccer_match} | ||
context "when logged in" do | ||
before do | ||
log_in user | ||
get :index, params: {match_id: match.id} | ||
end | ||
|
||
it "render index template" do | ||
expect(response).to render_template :index | ||
end | ||
|
||
it "check match" do | ||
expect(assigns(:match)).to eq(match) | ||
end | ||
end | ||
|
||
context "when match not found" do | ||
before do | ||
log_in user | ||
get :index, params: {match_id: -1} | ||
end | ||
|
||
it "flag warning" do | ||
expect(flash[:warning]).to eq I18n.t("bets.index.not_found_match") | ||
end | ||
|
||
it "redirect to root_path" do | ||
expect(response).to redirect_to root_path | ||
end | ||
end | ||
|
||
context "when not login" do | ||
before do | ||
get :index, params: {match_id: match.id} | ||
end | ||
|
||
it "render index" do | ||
expect(response).to redirect_to login_path | ||
end | ||
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,22 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe StaticPagesController, type: :controller do | ||
describe "GET home" do | ||
it "render home" do | ||
get :home | ||
expect(response).to render_template(:home) | ||
end | ||
end | ||
describe "GET help" do | ||
it "render help" do | ||
get :help | ||
expect(response).to render_template(:help) | ||
end | ||
end | ||
describe "GET about" do | ||
it "render about" do | ||
get :about | ||
expect(response).to render_template(:about) | ||
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,9 @@ | ||
FactoryBot.define do | ||
factory :soccer_match do | ||
home_id {1} | ||
guest_id {2} | ||
tournament_id {1} | ||
time {Time.now} | ||
status {0} | ||
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,9 @@ | ||
FactoryBot.define do | ||
factory :user do | ||
name {Faker::Name.name} | ||
email {Faker::Internet.email} | ||
password {"123456"} | ||
password_confirmation {"123456"} | ||
admin {1} | ||
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