Files
nairobi/spec/system/stats_spec.rb
Javi Martín 92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00

44 lines
1.2 KiB
Ruby

require "rails_helper"
describe "Stats" do
context "Summary" do
scenario "General" do
create(:debate)
2.times { create(:proposal) }
3.times { create(:comment, commentable: Debate.first) }
4.times { create(:visit) }
visit stats_path
expect(page).to have_content "DEBATES\n1"
expect(page).to have_content "PROPOSALS\n2"
expect(page).to have_content "COMMENTS\n3"
expect(page).to have_content "VISITS\n4"
end
scenario "Votes" do
create(:debate, voters: Array.new(1) { create(:user) })
create(:proposal, voters: Array.new(2) { create(:user) })
create(:comment, voters: Array.new(3) { create(:user) })
visit stats_path
expect(page).to have_content "VOTES ON DEBATES\n1"
expect(page).to have_content "VOTES ON PROPOSALS\n2"
expect(page).to have_content "VOTES ON COMMENTS\n3"
expect(page).to have_content "TOTAL VOTES\n6"
end
scenario "Users" do
1.times { create(:user, :level_three) }
2.times { create(:user, :level_two) }
2.times { create(:user) }
visit stats_path
expect(page).to have_content "VERIFIED USERS\n3"
expect(page).to have_content "UNVERIFIED USERS\n2"
end
end
end