diff options
-rw-r--r-- | app/models/profile_photo.rb | 12 | ||||
-rw-r--r-- | spec/models/profile_photo_spec.rb | 22 |
2 files changed, 23 insertions, 11 deletions
diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb index 322ebe53c..6c3b2cfa0 100644 --- a/app/models/profile_photo.rb +++ b/app/models/profile_photo.rb @@ -70,21 +70,25 @@ class ProfilePhoto < ActiveRecord::Base def data_and_draft_checks if self.data.nil? - errors.add(:data, N_("Please choose a file containing your photo.")) + errors.add(:data, _("Please choose a file containing your photo.")) return end if self.image.nil? - errors.add(:data, N_("Couldn't understand the image file that you uploaded. PNG, JPEG, GIF and many other common image file formats are supported.")) + errors.add(:data, _("Couldn't understand the image file that you uploaded. PNG, JPEG, GIF and many other common image file formats are supported.")) return end if self.image.format != 'PNG' - errors.add(:data, N_("Failed to convert image to a PNG")) + errors.add(:data, _("Failed to convert image to a PNG")) end if !self.draft && (self.image.columns != WIDTH || self.image.rows != HEIGHT) - errors.add(:data, N_("Failed to convert image to the correct size: at {{cols}}x{{rows}}, need {{width}}x{{height}}", :cols => self.image.columns, :rows => self.image.rows, :width => WIDTH, :height => HEIGHT)) + errors.add(:data, _("Failed to convert image to the correct size: at {{cols}}x{{rows}}, need {{width}}x{{height}}", + :cols => self.image.columns, + :rows => self.image.rows, + :width => WIDTH, + :height => HEIGHT)) end if self.draft && self.user_id diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb index 0e157e2c5..e70f474a0 100644 --- a/spec/models/profile_photo_spec.rb +++ b/spec/models/profile_photo_spec.rb @@ -10,12 +10,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe ProfilePhoto, "when constructing a new photo" do +describe ProfilePhoto, "when constructing a new photo" do - before do + before do @mock_user = mock_model(User) end - + it 'should take no image as invalid' do profile_photo = ProfilePhoto.new(:data => nil, :user => @mock_user) profile_photo.valid?.should == false @@ -26,7 +26,15 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.valid?.should == false end - it 'should accept and convert a PNG to right size' do + it 'should translate a no image error message' do + I18n.with_locale(:es) do + profile_photo = ProfilePhoto.new(:data => nil, :user => @mock_user) + profile_photo.valid?.should == false + profile_photo.errors[:data].should == ['Por favor elige el fichero que contiene tu foto'] + end + end + + it 'should accept and convert a PNG to right size' do data = load_file_fixture("parrot.png") profile_photo = ProfilePhoto.new(:data => data, :user => @mock_user) profile_photo.valid?.should == true @@ -35,7 +43,7 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.image.rows.should == 96 end - it 'should accept and convert a JPEG to right format and size' do + it 'should accept and convert a JPEG to right format and size' do data = load_file_fixture("parrot.jpg") profile_photo = ProfilePhoto.new(:data => data, :user => @mock_user) profile_photo.valid?.should == true @@ -44,7 +52,7 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.image.rows.should == 96 end - it 'should accept a draft PNG and not resize it' do + it 'should accept a draft PNG and not resize it' do data = load_file_fixture("parrot.png") profile_photo = ProfilePhoto.new(:data => data, :draft => true) profile_photo.valid?.should == true @@ -53,6 +61,6 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.image.rows.should == 289 end - + end |