diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/parrot.jpg | bin | 0 -> 15232 bytes | |||
-rw-r--r-- | spec/fixtures/parrot.png | bin | 0 -> 96431 bytes | |||
-rw-r--r-- | spec/models/profile_photo_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 32 | ||||
-rw-r--r-- | spec/spec_helper.rb | 6 |
5 files changed, 78 insertions, 0 deletions
diff --git a/spec/fixtures/parrot.jpg b/spec/fixtures/parrot.jpg Binary files differnew file mode 100644 index 000000000..22fd8e4de --- /dev/null +++ b/spec/fixtures/parrot.jpg diff --git a/spec/fixtures/parrot.png b/spec/fixtures/parrot.png Binary files differnew file mode 100644 index 000000000..77442a3d5 --- /dev/null +++ b/spec/fixtures/parrot.png diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb new file mode 100644 index 000000000..5b05c1205 --- /dev/null +++ b/spec/models/profile_photo_spec.rb @@ -0,0 +1,40 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe ProfilePhoto, "when constructing a new photo" do + + before do + #@request_event = mock_model(InfoRequestEvent, :xapian_mark_needs_index => true) + #@request = mock_model(InfoRequest, :info_request_events => [@request_event]) + #@user = mock_model(User) + end + + it 'should take no image as invalid' do + profile_photo = ProfilePhoto.new(:data => nil) + profile_photo.valid?.should == false + end + + it 'should take bad binary data as invalid' do + profile_photo = ProfilePhoto.new(:data => 'blahblahblah') + profile_photo.valid?.should == false + end + + it 'should accept and convert a PNG to right size' do + data = load_image_fixture("parrot.png") + profile_photo = ProfilePhoto.new(:data => data, :user => mock_model(User, :valid? => true)) + profile_photo.valid?.should == true + profile_photo.image.format.should == 'PNG' + profile_photo.image.columns.should == 96 + profile_photo.image.rows.should == 96 + end + + it 'should accept and convert a JPEG to right format and size' do + data = load_image_fixture("parrot.jpg") + profile_photo = ProfilePhoto.new(:data => data, :user => mock_model(User, :valid? => true)) + profile_photo.valid?.should == true + profile_photo.image.format.should == 'PNG' + profile_photo.image.columns.should == 96 + profile_photo.image.rows.should == 96 + end + +end + diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index db7753469..7de181300 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -216,3 +216,35 @@ describe User, " when making name and email address" do end +describe User, " when setting a profile photo" do + before do + @user = User.new + @user.name = "Sensible User" + @user.email = "sensible@localhost" + @user.password = "sensiblepassword" + end + + it "should attach it to the user" do + data = load_image_fixture("parrot.png") + profile_photo = ProfilePhoto.new(:data => data) + @user.set_profile_photo(profile_photo) + profile_photo.user.should == @user + end + +# it "should destroy old photos being replaced" do +# ProfilePhoto.count.should == 0 +# +# data_1 = load_image_fixture("parrot.png") +# profile_photo_1 = ProfilePhoto.new(:data => data_1) +# data_2 = load_image_fixture("parrot.jpg") +# profile_photo_2 = ProfilePhoto.new(:data => data_2) +# +# @user.set_profile_photo(profile_photo_1) +# @user.save! +# ProfilePhoto.count.should == 1 +# @user.set_profile_photo(profile_photo_2) +# @user.save! +# ProfilePhoto.count.should == 1 +# end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6852909a6..2af585d7a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,6 +31,12 @@ def receive_incoming_mail(email_name, email_to, email_from = 'geraldinequango@lo RequestMailer.receive(content) end +def load_image_fixture(image_name) + image_name = File.join(Spec::Runner.configuration.fixture_path, image_name) + content = File.read(image_name) + return content +end + def rebuild_xapian_index rebuild_name = File.dirname(__FILE__) + '/../script/rebuild-xapian-index' Kernel.system(rebuild_name) or raise "failed to launch rebuild-xapian-index" |