docbrown/spec/requests/dashboard_spec.rb
rhymes 6553f08d94 Rubocop cleanups (#1415)
* Update rubocop-todo.yml with new violations

* Fix Layout/EmptyLine* rules

* Fix Layout/Indentation* rules

* Fix remaining Layout/* rules

* Fix Lint/DuplicateMethods by removing unused accessor

* Fix Lint/IneffectiveAccessModifier

* Fix Lint/MissingCopEnableDirective

* Re-run rubocop auto gen config

* Fix Layout/RescueEnsureAlignment

* Fix Naming/* rules

* Fix some RSpec/* rules

* Fix typos

* Fix RSpec/LetBeforeExamples

* Series should only be an attr_writer, not an attr_accessor

* Fix RSpec/InstanceVariable

* Fix RSpec/InstanceVariable

* Fix RSpec/RepeatedDescription and RSpec/RepeatedExample

* Fix Style/ClassAndModuleChildren

* Fix Style/ConditionalAssignment

* Fix some Style/* rules

* Trigger Travis CI build because failing tests are not failing locally

* Revert "Fix Style/ClassAndModuleChildren"

This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
2019-01-02 11:20:02 -05:00

101 lines
2.8 KiB
Ruby

require "rails_helper"
RSpec.describe "Dashboards", type: :request do
let(:user) { create(:user) }
let(:second_user) { create(:user) }
let(:super_admin) { create(:user, :super_admin) }
let(:article) { create(:article, user_id: user.id) }
describe "GET /dashboard" do
context "when not logged in" do
it "redirects to /enter" do
get "/dashboard"
expect(response).to redirect_to("/enter")
end
end
context "when logged in" do
it "renders user's articles" do
login_as user
article
get "/dashboard"
expect(response.body).to include CGI.escapeHTML(article.title)
end
end
context "when logged in as a super admin" do
it "renders the specified user's articles" do
article
user
login_as super_admin
get "/dashboard/#{user.username}"
expect(response.body).to include CGI.escapeHTML(article.title)
end
end
end
describe "GET /dashboard/organization" do
let(:organization) { create(:organization) }
context "when not logged in" do
it "redirects to /enter" do
get "/dashboard/organization"
expect(response).to redirect_to("/enter")
end
end
context "when logged in" do
it "renders user's organization articles" do
user.update(organization_id: organization.id, org_admin: true)
article.update(organization_id: organization.id)
login_as user
get "/dashboard/organization"
expect(response.body).to include "#{CGI.escapeHTML(organization.name)} ("
end
end
end
describe "GET /dashboard/following_users" do
context "when not logged in" do
it "redirects to /enter" do
get "/dashboard/following_users"
expect(response).to redirect_to("/enter")
end
end
context "when logged in" do
it "renders the current user's followings" do
user.follow second_user
login_as user
get "/dashboard/following_users"
expect(response.body).to include CGI.escapeHTML(second_user.name)
end
it "renders the current user's tag followings" do
user.follow second_user
tag = create(:tag)
user.follow tag
login_as user
get "/dashboard/following"
expect(response.body).to include CGI.escapeHTML(tag.name)
end
end
end
describe "GET /dashboard/user_followers" do
context "when not logged in" do
it "redirects to /enter" do
get "/dashboard/user_followers"
expect(response).to redirect_to("/enter")
end
end
context "when logged in" do
it "renders the current user's followers" do
second_user.follow user
login_as user
get "/dashboard/user_followers"
expect(response.body).to include CGI.escapeHTML(second_user.name)
end
end
end
end