Settings are stored in the database, and so any changes to the settings done during the tests are automatically rolled back between one test and the next one. There were also a few places where we weren't using an `after` block but changing the setting at the end of the test.
57 lines
1.7 KiB
Ruby
57 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Retrieves number of supports for the successful proposal" do
|
|
let(:created_at) { Date.current.beginning_of_day - 9.days }
|
|
let(:proposal) { create(:proposal, created_at: created_at, published_at: created_at) }
|
|
|
|
before do
|
|
@successful_proposal_id = Setting["proposals.successful_proposal_id"]
|
|
Setting["proposals.successful_proposal_id"] = proposal.id
|
|
|
|
8.times do |i|
|
|
user = create(:user, :verified)
|
|
Vote.create!(
|
|
votable: proposal,
|
|
voter: user,
|
|
vote_weight: 1,
|
|
created_at: proposal.created_at + i.days,
|
|
updated_at: proposal.created_at + i.days
|
|
)
|
|
end
|
|
|
|
sign_in(proposal.author)
|
|
end
|
|
|
|
it "returns the number of supports grouped by day" do
|
|
get proposal_dashboard_successful_supports_path(proposal, format: :json)
|
|
|
|
json = JSON.parse(response.body, symbolize_names: true)
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(json.length).to eq(10)
|
|
expect(json.values.last).to eq(8)
|
|
end
|
|
|
|
it "returns the number of supports grouped by week" do
|
|
get proposal_dashboard_successful_supports_path(proposal, group_by: "week", format: :json)
|
|
|
|
json = JSON.parse(response.body, symbolize_names: true)
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(json.length).to be >= 2
|
|
expect(json.length).to be <= 3
|
|
expect(json.values.last).to eq(8)
|
|
end
|
|
|
|
it "returns the number of supports grouped by month" do
|
|
get proposal_dashboard_successful_supports_path(proposal, group_by: "month", format: :json)
|
|
|
|
json = JSON.parse(response.body, symbolize_names: true)
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(json.length).to be >= 1
|
|
expect(json.length).to be <= 2
|
|
expect(json.values.last).to eq(8)
|
|
end
|
|
end
|