4.7 test that user ratings are shown on the user's page

This commit is contained in:
Aaro Koivukangas
2023-11-11 12:03:22 +02:00
parent afc123126a
commit 80c4a6bfca
4 changed files with 37 additions and 1 deletions
+1
View File
@@ -1,4 +1,5 @@
<h2>List of ratings</h2>
<p>There is <%= pluralize @ratings.count, "rating" %></p>
<ul>
<% @ratings.each do |rating| %>
+1 -1
View File
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :user do
username { "Möötti" }
username { "MööttiTesti" }
password { "Unsecure1" }
password_confirmation { "Unsecure1" }
end
+14
View File
@@ -0,0 +1,14 @@
require "rails_helper"
describe "Ratings Page" do
it "should not contain anything in the beginning" do
visit ratings_path
expect(page).to have_content "List of ratings"
expect(page).to have_content "There is 0 ratings"
FactoryBot.create :rating
visit ratings_path
expect(page).to have_content "There is 1 rating"
end
end
+21
View File
@@ -0,0 +1,21 @@
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 }
it "should display only user's ratings" do
# this took over an hour to remember to do... :D
rating1.save()
rating2.save()
visit user_path(user.id)
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"
end
end