-
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.
Merge pull request #149 from loftwah/dl/default-avatar-bug
Dl/default avatar bug
- Loading branch information
Showing
6 changed files
with
81 additions
and
99 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
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 |
---|---|---|
|
@@ -6,55 +6,35 @@ | |
end | ||
|
||
describe "POST #create" do | ||
let(:valid_attributes) { | ||
{ email: "[email protected]", password: "password", password_confirmation: "password", | ||
username: "testuser", full_name: "Test User", tags: "tag1,tag2", avatar_border: "white", invite_code: "POWEROVERWHELMING" } | ||
} | ||
let(:valid_attributes) { | ||
{ email: "[email protected]", password: "password", password_confirmation: "password", | ||
username: "testuser", full_name: "Test User", tags: "tag1,tag2", avatar_border: "white", invite_code: "POWEROVERWHELMING" } | ||
} | ||
|
||
context "when sign-ups are enabled" do | ||
before do | ||
allow(Rails.application.config).to receive(:sign_ups_open).and_return(true) | ||
end | ||
|
||
it "creates a new User" do | ||
expect { | ||
post :create, params: { user: valid_attributes } | ||
}.to change(User, :count).by(1) | ||
end | ||
context "when sign-ups are enabled" do | ||
before do | ||
allow(Rails.application.config).to receive(:sign_ups_open).and_return(true) | ||
end | ||
|
||
it "correctly processes tags" do | ||
it "creates a new User" do | ||
expect { | ||
post :create, params: { user: valid_attributes } | ||
user = User.last | ||
tags = user.tags.is_a?(String) ? JSON.parse(user.tags) : user.tags | ||
expect(tags).to eq(["tag1", "tag2"]) | ||
end | ||
}.to change(User, :count).by(1) | ||
end | ||
|
||
context "when sign-ups are disabled" do | ||
before do | ||
allow(Rails.application.config).to receive(:sign_ups_open).and_return(false) | ||
end | ||
|
||
it "does not create a new User without a valid invite code and redirects to root path" do | ||
invalid_attributes = valid_attributes.merge(invite_code: "INVALIDCODE") | ||
expect { | ||
post :create, params: { user: invalid_attributes } | ||
}.not_to change(User, :count) | ||
expect(response).to redirect_to(root_path) | ||
expect(flash[:alert]).to eq("Sign-ups are currently disabled.") | ||
end | ||
|
||
it "creates a new User with a valid invite code" do | ||
expect(controller).to receive(:after_sign_up_path_for).with(instance_of(User)).and_return("/path/to/redirect") | ||
it "sets the fallback avatar URL if none is provided" do | ||
post :create, params: { user: valid_attributes.merge(avatar: nil) } | ||
user = User.last | ||
expect(user.avatar).to eq('https://pbs.twimg.com/profile_images/1581014308397502464/NPogKMyk_400x400.jpg') | ||
end | ||
|
||
expect { | ||
post :create, params: { user: valid_attributes } | ||
}.to change(User, :count).by(1) | ||
|
||
expect(response).to redirect_to("/path/to/redirect") | ||
end | ||
it "handles invalid avatar URLs and sets the fallback URL" do | ||
post :create, params: { user: valid_attributes.merge(avatar: 'http://invalid-url.com/avatar.jpg') } | ||
user = User.last | ||
expect(user.avatar).to eq('https://pbs.twimg.com/profile_images/1581014308397502464/NPogKMyk_400x400.jpg') | ||
end | ||
end | ||
end | ||
|
||
describe "PUT #update" do | ||
let(:user) { create(:user, tags: ["old_tag1", "old_tag2"].to_json) } | ||
|
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