diff options
-rw-r--r-- | app/models/censor_rule.rb | 2 | ||||
-rw-r--r-- | app/models/change_email_validator.rb | 2 | ||||
-rw-r--r-- | app/models/comment.rb | 2 | ||||
-rw-r--r-- | app/models/contact_validator.rb | 2 | ||||
-rw-r--r-- | app/models/exim_log.rb | 2 | ||||
-rw-r--r-- | app/models/exim_log_done.rb | 2 | ||||
-rw-r--r-- | app/models/holiday.rb | 2 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 2 | ||||
-rw-r--r-- | app/models/info_request.rb | 2 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 2 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 2 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 2 | ||||
-rw-r--r-- | app/models/profile_photo.rb | 21 | ||||
-rw-r--r-- | app/models/public_body.rb | 2 | ||||
-rw-r--r-- | app/models/public_body_tag.rb | 2 | ||||
-rw-r--r-- | app/models/raw_email.rb | 2 | ||||
-rw-r--r-- | app/models/track_thing.rb | 2 | ||||
-rw-r--r-- | app/models/track_things_sent_email.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/models/user_info_request_sent_alert.rb | 2 | ||||
-rw-r--r-- | db/migrate/085_draft_profile_photo.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 5 | ||||
-rw-r--r-- | spec/models/profile_photo_spec.rb | 2 |
23 files changed, 46 insertions, 29 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb index 334a6fc50..40490181a 100644 --- a/app/models/censor_rule.rb +++ b/app/models/censor_rule.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: censor_rules # diff --git a/app/models/change_email_validator.rb b/app/models/change_email_validator.rb index 26a6ef35f..5bdf89ee4 100644 --- a/app/models/change_email_validator.rb +++ b/app/models/change_email_validator.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: change_email_validators # diff --git a/app/models/comment.rb b/app/models/comment.rb index e7a877732..f6f8529f5 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: comments # diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb index 57579ecc2..7d4fad0e1 100644 --- a/app/models/contact_validator.rb +++ b/app/models/contact_validator.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: contact_validators # diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb index 62caff047..2d4102623 100644 --- a/app/models/exim_log.rb +++ b/app/models/exim_log.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: exim_logs # diff --git a/app/models/exim_log_done.rb b/app/models/exim_log_done.rb index cc3a3d315..6fb744821 100644 --- a/app/models/exim_log_done.rb +++ b/app/models/exim_log_done.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: exim_log_dones # diff --git a/app/models/holiday.rb b/app/models/holiday.rb index 711b0eb25..ef9c55aed 100644 --- a/app/models/holiday.rb +++ b/app/models/holiday.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: holidays # diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index cdf0d61f2..fcbea4990 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: incoming_messages # diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 1f4cc0000..63daad25d 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: info_requests # diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 19f3598b6..2bbb69977 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: info_request_events # diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 003b52e15..cffe1b281 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: outgoing_messages # diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 5d296f3ce..98d36fe65 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: post_redirects # diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb index cd74c3580..108e34110 100644 --- a/app/models/profile_photo.rb +++ b/app/models/profile_photo.rb @@ -1,11 +1,12 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: profile_photos # # id :integer not null, primary key # data :binary not null # user_id :integer +# draft :boolean default(false), not null # # models/profile_photo.rb: @@ -25,14 +26,11 @@ class ProfilePhoto < ActiveRecord::Base belongs_to :user - attr_accessor :draft - # deliberately don't strip_attributes, so keeps raw photo properly # convert binary data blob into ImageMagick image when assigned attr_accessor :image - def data=(data) - write_attribute(:data, data) + def after_initialize if data.nil? self.image = nil return @@ -66,7 +64,8 @@ class ProfilePhoto < ActiveRecord::Base self.image.format = 'PNG' altered = true end - if image.columns != WIDTH || image.rows != HEIGHT + # draft images are before the user has cropped them + if !self.draft && (image.columns != WIDTH || image.rows != HEIGHT) image.resize_to_fill!(WIDTH, HEIGHT) altered = true end @@ -90,9 +89,17 @@ class ProfilePhoto < ActiveRecord::Base errors.add(:data, "^Failed to convert image to a PNG") end - if self.image.columns != WIDTH || self.image.rows != HEIGHT + if !self.draft && (self.image.columns != WIDTH || self.image.rows != HEIGHT) errors.add(:data, "^Failed to convert image to the correct size: at #{self.image.columns}x#{self.image.rows}, need #{WIDTH}x#{HEIGHT}") end + + if self.draft && self.user_id + raise "Internal error, draft pictures must not have a user" + end + + if !self.draft && !self.user_id + raise "Internal error, real pictures must have a user" + end end end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index c071ed339..ca7d39c74 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: public_bodies # diff --git a/app/models/public_body_tag.rb b/app/models/public_body_tag.rb index 9efe761a1..6ed698431 100644 --- a/app/models/public_body_tag.rb +++ b/app/models/public_body_tag.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: public_body_tags # diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 9df3aedb3..aab2474a2 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: raw_emails # diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 1935fdf51..6d32e59d1 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: track_things # diff --git a/app/models/track_things_sent_email.rb b/app/models/track_things_sent_email.rb index 66a8ab457..129bf19a4 100644 --- a/app/models/track_things_sent_email.rb +++ b/app/models/track_things_sent_email.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: track_things_sent_emails # diff --git a/app/models/user.rb b/app/models/user.rb index 23843be06..dcc92d5e3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: users # diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb index a3c2de304..02bb22b40 100644 --- a/app/models/user_info_request_sent_alert.rb +++ b/app/models/user_info_request_sent_alert.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 84 +# Schema version: 85 # # Table name: user_info_request_sent_alerts # diff --git a/db/migrate/085_draft_profile_photo.rb b/db/migrate/085_draft_profile_photo.rb new file mode 100644 index 000000000..c0b507485 --- /dev/null +++ b/db/migrate/085_draft_profile_photo.rb @@ -0,0 +1,9 @@ +class DraftProfilePhoto < ActiveRecord::Migration + def self.up + add_column :profile_photos, :draft, :boolean, :default => false, :null => false + end + + def self.down + raise "No reverse migration" + end +end diff --git a/db/schema.rb b/db/schema.rb index f2a8812b0..a6d5e8f55 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 84) do +ActiveRecord::Schema.define(:version => 85) do create_table "acts_as_xapian_jobs", :force => true do |t| t.string "model", :null => false @@ -144,8 +144,9 @@ ActiveRecord::Schema.define(:version => 84) do add_index "post_redirects", ["updated_at"], :name => "index_post_redirects_on_updated_at" create_table "profile_photos", :force => true do |t| - t.binary "data", :null => false + t.binary "data", :null => false t.integer "user_id" + t.boolean "draft", :default => false, :null => false end create_table "public_bodies", :force => true do |t| diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb index 1e33c5b61..7811fb5fc 100644 --- a/spec/models/profile_photo_spec.rb +++ b/spec/models/profile_photo_spec.rb @@ -35,7 +35,7 @@ describe ProfilePhoto, "when constructing a new photo" do it 'should accept a draft PNG and not resize it' do data = load_file_fixture("parrot.png") - profile_photo = ProfilePhoto.new(:draft => true, :data => data) + profile_photo = ProfilePhoto.new(:data => data, :draft => true) profile_photo.valid?.should == true profile_photo.image.format.should == 'PNG' profile_photo.image.columns.should == 198 |