mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
bugfix: rake db:reset RAILS_ENV=test also runs db:seed => test db is not empty
This commit is contained in:
@@ -1,19 +1,31 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Beers page" do
|
||||
it "should display all beers in the database" do
|
||||
let(:brewery){ FactoryBot.create :brewery }
|
||||
let(:beer){ FactoryBot.create :beer }
|
||||
|
||||
it "should be empty before tests" do
|
||||
visit beers_path
|
||||
expect(page).to have_content "Beers"
|
||||
expect(page).to have_content "Iso 3"
|
||||
expect(page).to have_content "Karhu"
|
||||
expect(page).to have_content "Tuplahumala"
|
||||
expect(page).to have_content "Huvila Pale Ale"
|
||||
expect(page).to have_content "X Porter"
|
||||
expect(page).to have_content "Hefeweizen"
|
||||
expect(page).to have_content "Helles"
|
||||
|
||||
expect(page).to_not have_content "Iso 3"
|
||||
expect(page).to_not have_content "Something good"
|
||||
expect(Beer.all.count).to be_equal(0)
|
||||
end
|
||||
|
||||
it "should display all beers in the database" do
|
||||
brewery.save()
|
||||
beer.save()
|
||||
|
||||
visit beers_path
|
||||
expect(page).to have_content "Beers"
|
||||
expect(page).to have_content "Something good"
|
||||
|
||||
end
|
||||
|
||||
it "should be able to add a new beer" do
|
||||
brewery.save()
|
||||
|
||||
visit new_beer_path
|
||||
expect(page).to have_content "New beer"
|
||||
expect(page).to_not have_content "New fancy test beer"
|
||||
@@ -23,6 +35,7 @@ describe "Beers page" do
|
||||
|
||||
expect(page).to have_content "Beer was successfully created"
|
||||
expect(page).to have_content "New fancy test beer"
|
||||
expect(Beer.find_by(name: "New fancy test beer").nil?).to be_equal(false)
|
||||
end
|
||||
|
||||
it "should not be able to add a new beer without a proper beer name" do
|
||||
|
||||
@@ -4,7 +4,6 @@ describe "Breweries page" do
|
||||
it "should not have any before created" do
|
||||
visit breweries_path
|
||||
expect(page).to have_content "Breweries"
|
||||
# Has all of the default Breweries
|
||||
expect(Brewery.count).to eq 3
|
||||
expect(Brewery.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,16 @@ require "rails_helper"
|
||||
|
||||
describe "User Page" do
|
||||
let(:user) { FactoryBot.create :user }
|
||||
let(:rating1) { Rating.create score: 20, user_id: user.id, beer_id: Beer.first.id }
|
||||
let(:rating2) { Rating.create score: 30, user_id: user.id, beer_id: Beer.first.id }
|
||||
let(:brewery) { FactoryBot.create :brewery }
|
||||
let(:beer) { FactoryBot.create :beer }
|
||||
let(:rating1) { Rating.create score: 20, user_id: user.id, beer_id: beer.id }
|
||||
let(:rating2) { Rating.create score: 30, user_id: user.id, beer_id: beer.id }
|
||||
|
||||
it "should display only user's ratings" do
|
||||
# this took over an hour to remember to do... :D
|
||||
user.save()
|
||||
brewery.save()
|
||||
beer.save()
|
||||
rating1.save()
|
||||
rating2.save()
|
||||
|
||||
@@ -15,11 +20,12 @@ describe "User Page" do
|
||||
expect(page).to have_content "Username: MööttiTesti"
|
||||
expect(page).to have_content "Has made 2 ratings"
|
||||
|
||||
expect(page).to have_content "Iso 3 20"
|
||||
expect(page).to have_content "Iso 3 30"
|
||||
expect(page).to have_content "Something good 20"
|
||||
expect(page).to have_content "Something good 30"
|
||||
end
|
||||
|
||||
it "before login doesn't show Delete button" do
|
||||
user.save()
|
||||
rating1.save()
|
||||
rating2.save()
|
||||
|
||||
@@ -28,6 +34,7 @@ describe "User Page" do
|
||||
end
|
||||
|
||||
it "after login shows Delete button" do
|
||||
user.save()
|
||||
rating1.save()
|
||||
rating2.save()
|
||||
|
||||
|
||||
@@ -47,6 +47,12 @@ RSpec.configure do |config|
|
||||
# triggering implicit auto-inclusion in groups with matching metadata.
|
||||
config.shared_context_metadata_behavior = :apply_to_host_groups
|
||||
|
||||
# https://stackoverflow.com/questions/25877734/rails-4-how-to-reset-test-database
|
||||
#config.after :all do
|
||||
# ActiveRecord::Base.subclasses.each(&:delete_all)
|
||||
#end
|
||||
|
||||
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
=begin
|
||||
|
||||
Reference in New Issue
Block a user