* added organization policy + spec * user specs for is_org_admin? * added authroize to organization controller * admin policy + specs * deleted enforce admin due to pundit policy redundancy * applied admin policy to entire admin namespace * refactoring analytics controller WIP - wanna test codeship * Add protection against reactions to unpublished articles (#473) * Add chat channel policy and spec (#474) * Add comment policy and specs (#475) * Fix edge case with apostrophes * Add comment policy and specs * Add login for deleting comment spec * Change test to raise pundit error instead of 404 * Clean up comment destroy request specs * Remove redundant raise * Whitelist columns on to_json call (#477) * Add pundit policy for several controllers (#476) * Add pundit policy for several controllers * Adjust video spec * Fix tag request specs * Add proper twilio tokens request specs * Remove puts statements * Add a couple basic request specs (#478) * Add a few tests and fix user tag color bug (#482) * Refactor handle_tag_index in stories_controller (#481) * Modify valid_request_origin? (#483) * Add misc specs and remove banned attribute from user model (#484) * Fix missing Cloudinary tags and misc specs (#486) * removing current_user_is_admin? to use .is_admin? method * added missing org policy routes * Add comment for all public controllers * Fix edge case for test * Authorize mod controller and add specs * Refactor methods via inheritance and use only super_admin role * Create policy method for analytics via article_policy and refactor * Capitalize all buttons in dashboard page * Fix org tests and remove old admin test * Use only happy path for analytics * Fix tests to use Pundit error * Update org_policy spec
94 lines
2.6 KiB
Ruby
94 lines
2.6 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"
|
|
is_expected.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"
|
|
is_expected.to redirect_to("/enter")
|
|
end
|
|
end
|
|
|
|
context "when logged in" do
|
|
it "renders user's organization articles" do
|
|
organization = create(:organization)
|
|
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.upcase)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "GET /dashboard/following_users" do
|
|
context "when not logged in" do
|
|
it "redirects to /enter" do
|
|
get "/dashboard/following_users"
|
|
is_expected.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
|
|
end
|
|
end
|
|
|
|
describe "GET /dashboard/user_followers" do
|
|
context "when not logged in" do
|
|
it "redirects to /enter" do
|
|
get "/dashboard/user_followers"
|
|
is_expected.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
|