-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Analytics', type: :request do | ||
describe 'GET /index' do | ||
describe 'GET /:username/analytics' do | ||
let(:user) { create(:user) } | ||
|
||
before do | ||
sign_in user | ||
end | ||
|
||
it 'returns http success' do | ||
get analytics_path | ||
puts response.body # Add this line to print the response body in case of an error | ||
get user_analytics_path(username: user.username) | ||
expect(response).to have_http_status(:success) | ||
end | ||
|
||
it 'renders the correct content' do | ||
get user_analytics_path(username: user.username) | ||
expect(response.body).to include('Analytics') # Adjust this to match your actual content | ||
end | ||
|
||
context "when viewing another user's analytics" do | ||
let(:other_user) { create(:user, public_analytics: true) } | ||
|
||
it "allows viewing public analytics" do | ||
get user_analytics_path(username: other_user.username) | ||
expect(response).to have_http_status(:success) | ||
end | ||
|
||
it "redirects when trying to view private analytics" do | ||
other_user.update(public_analytics: false) | ||
get user_analytics_path(username: other_user.username) | ||
expect(response).to redirect_to(root_path) | ||
end | ||
end | ||
end | ||
end | ||
end |