* Update Travis.yml * Update README * Update README * Adjust test to not rely on env vars * Update encryption * Refactor * Update env key * Stub AWS calls * Create ApplicationConfig * Fix specs * Fix lint * Update ApplicationConfig * Remove travis env vars * Fix lint * Extend character limit to 100 * Add env to travis * Take out auto-restart after deploy * Immediately discarded test cache * Stub GA in request specs * Stub Pusher * Fix broken specs * Update fixture * Add CodeClimate id * Change CodeClimate key * Remove merge mistakes * WIP * Add Envied gem & Change README * Add missing keys * Add missing key * Update fixture * Fix broken spec * Add Slack Notification for Travis * Fix wording * Fix typo
41 lines
1.5 KiB
Ruby
41 lines
1.5 KiB
Ruby
require "rails_helper"
|
|
|
|
vcr_option = {
|
|
cassette_name: "google_api_request_spec",
|
|
}
|
|
|
|
RSpec.describe "Analytics", type: :request, vcr: vcr_option do
|
|
describe "GET /analytics" do
|
|
context "when signed in as an authorized user" do
|
|
let(:user) { create(:user, :analytics) }
|
|
let(:article1) { create(:article, user_id: user.id) }
|
|
let(:article2) { create(:article, user_id: user.id) }
|
|
let(:ga_double) { instance_double(GoogleAnalytics) }
|
|
|
|
before do
|
|
allow(GoogleAnalytics).to receive(:new).and_return(ga_double)
|
|
allow(ga_double).to receive(:create_service_account_credential).and_return({})
|
|
allow(ga_double).to receive(:get_pageviews) do
|
|
{ article1.id.to_s => "0", article2.id.to_s => "0" }
|
|
end
|
|
login_as user
|
|
end
|
|
|
|
it "raise ParameterMissing if no proper params is given" do
|
|
expect { get "/analytics" }.to raise_error ActionController::ParameterMissing
|
|
end
|
|
|
|
it "returns pageviews" do
|
|
get "/analytics?article_ids=#{article1.id},#{article2.id}"
|
|
expect(JSON.parse(response.body)).to eq(article1.id.to_s => "0", article2.id.to_s => "0")
|
|
end
|
|
|
|
it "returns pageviews for super_admins" do
|
|
user.remove_role :analytics_beta_tester
|
|
user.add_role :super_admin
|
|
get "/analytics?article_ids=#{article1.id},#{article2.id}"
|
|
expect(JSON.parse(response.body)).to eq(article1.id.to_s => "0", article2.id.to_s => "0")
|
|
end
|
|
end
|
|
end
|
|
end
|