Skip to content

Commit

Permalink
Merge pull request #29 from binhpt-1239/test_rspec
Browse files Browse the repository at this point in the history
Rspec controller static_pages and bets
  • Loading branch information
vanvtt-0952 authored Apr 5, 2022
2 parents 1f8ce66 + 6b77fa3 commit e56143c
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .framgia-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ project_type: ruby
test:
rubocop:
command: bundle exec rubocop --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter --no-color --out .framgia-ci-reports/rubocop.xml app/ lib/
spec:
rspec:
command: bundle exec rspec --format html --out .framgia-ci-reports/rspec.html spec/
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ config/environments/*.local.yml
# Ignore application configuration
/config/application.yml

#spec
/spec/helpers/*.rb
/spec/requests/*.rb
/spec/views/*

/.vscode

#coverage
#
/coverage
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ end
group :test do
gem "capybara", ">= 2.15"
gem "factory_bot_rails"
gem "rails-controller-testing"
gem "rspec-rails", "~> 4.0.1"
gem "rubocop", "~> 0.74.0", require: false
gem "rubocop-checkstyle_formatter", require: false
gem "rubocop-rails", "~> 2.3.2", require: false
gem "rspec-rails", "~> 4.0.1"
gem "rails-controller-testing"
gem "selenium-webdriver"
gem "simplecov"
gem "simplecov-rcov"
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ GEM
bundler (>= 1.3.0)
railties (= 6.0.4.7)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand Down Expand Up @@ -315,6 +319,7 @@ DEPENDENCIES
pagy
puma (~> 4.1)
rails (~> 6.0.4, >= 6.0.4.6)
rails-controller-testing
rails-i18n
rspec-rails (~> 4.0.1)
rubocop (~> 0.74.0)
Expand Down
48 changes: 48 additions & 0 deletions spec/controller/bets_controller_spec.rb
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
22 changes: 22 additions & 0 deletions spec/controller/static_pages_controller_spec.rb
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
9 changes: 9 additions & 0 deletions spec/factories/soccer_matchs.rb
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
9 changes: 9 additions & 0 deletions spec/factories/users.rb
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
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
config.include FactoryBot::Syntax::Methods
end

0 comments on commit e56143c

Please sign in to comment.