diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4a19dd27f..2d2e0c3c6 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -17,6 +17,8 @@ class Budget acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + has_attached_file :image, styles: { large: "600x600>", medium: "300x300>", thumb: "100x100>" } + belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :heading belongs_to :group @@ -28,9 +30,6 @@ class Budget has_many :comments, as: :commentable has_many :milestones - has_attached_file :image, styles: { large: "600x600>" ,medium: "300x300>", thumb: "100x100>" } - validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/ - validates :title, presence: true validates :author, presence: true validates :description, presence: true @@ -41,6 +40,7 @@ class Budget validates :title, length: { in: 4..Budget::Investment.title_max_length } validates :description, length: { maximum: Budget::Investment.description_max_length } validates :terms_of_service, acceptance: { allow_nil: false }, on: :create + validates_attachment :image, content_type: { content_type: ["image/jpeg"] } scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) } scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) } diff --git a/spec/fixtures/files/logo_header.gif b/spec/fixtures/files/logo_header.gif new file mode 100644 index 000000000..4bfddd410 Binary files /dev/null and b/spec/fixtures/files/logo_header.gif differ diff --git a/spec/fixtures/files/logo_header.jpg b/spec/fixtures/files/logo_header.jpg new file mode 100644 index 000000000..aeed9e524 Binary files /dev/null and b/spec/fixtures/files/logo_header.jpg differ diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index df32853ad..dda046275 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -29,6 +29,30 @@ describe Budget::Investment do end end + describe "#image" do + + describe "extesion" do + it "should not be valid with '.png' extension" do + investment.image = File.new("spec/fixtures/files/logo_header.png") + + expect(investment).to_not be_valid + end + + it "should not be valid with '.gif' extension" do + investment.image = File.new("spec/fixtures/files/logo_header.gif") + + expect(investment).to_not be_valid + end + + it "should be valid with '.jpg' extension" do + investment.image = File.new("spec/fixtures/files/logo_header.jpg") + + expect(investment).to be_valid + end + end + + end + it "sanitizes description" do investment.description = "" investment.valid?