Skip to content

Commit

Permalink
Avatar url now accepts empty string
Browse files Browse the repository at this point in the history
Empty external avatar url is valid value. If user has empty avatar url then gravatar will be used instead.
  • Loading branch information
Artem committed Aug 7, 2013
1 parent dac2f26 commit fffd470
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
7 changes: 1 addition & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ def suspend!
# and if image extension is allowed
def check_external_avatar
# avatar url is not required
if self.avatar_url.nil?
return
end

if self.avatar_url.empty?
errors.add(:avatar_url, "cannot be empty")
if self.avatar_url.nil? or self.avatar_url.empty?
return
end

Expand Down
11 changes: 2 additions & 9 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
context "check url" do
subject { FactoryGirl.build(:user) }

it "should accept non-empty small image with allowed extension" do
it "should accept small image url with allowed extension" do
subject.avatar_url = "https://github.global.ssl.fastly.net/images/icons/emoji/+1.png"
expect(subject.save).to be_true
expect(subject).to be_valid
end

it "should not accept extension that is not allowed in config" do
it "should not accept url with extension that is not allowed in config" do
# a 35KB midi sound
subject.avatar_url = "http://saya.pianomidi.org/musica/lfals/a-asturias.mid"
expect(subject.save).to be_false
Expand All @@ -105,13 +105,6 @@
expect(subject).to_not be_valid
expect(subject.errors).to have_key(:avatar_url)
end

it "should not validate empty url as avatar" do
subject.avatar_url = ""
expect(subject.save).to be_false
expect(subject).to_not be_valid
expect(subject.errors).to have_key(:avatar_url)
end
end
end
end

0 comments on commit fffd470

Please sign in to comment.