Add image description to budget investments
This commit is contained in:
@@ -41,6 +41,8 @@ class Budget
|
||||
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"] }
|
||||
validates :image_description, presence: true, if: -> { image.present? }
|
||||
validates :image_description, length: { in: 4..Budget::Investment.title_max_length }, if: -> { image.present? }
|
||||
|
||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) }
|
||||
scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) }
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddImageDescriptionToBudgetInvestments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :budget_investments, :image_description, :string
|
||||
end
|
||||
end
|
||||
@@ -165,6 +165,7 @@ ActiveRecord::Schema.define(version: 20170918231410) do
|
||||
t.string "image_content_type"
|
||||
t.integer "image_file_size"
|
||||
t.datetime "image_updated_at"
|
||||
t.string "image_description"
|
||||
end
|
||||
|
||||
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
|
||||
@@ -256,10 +257,10 @@ ActiveRecord::Schema.define(version: 20170918231410) do
|
||||
t.string "visit_id"
|
||||
t.datetime "hidden_at"
|
||||
t.integer "flags_count", default: 0
|
||||
t.datetime "ignored_flag_at"
|
||||
t.integer "cached_votes_total", default: 0
|
||||
t.integer "cached_votes_up", default: 0
|
||||
t.integer "cached_votes_down", default: 0
|
||||
t.datetime "ignored_flag_at"
|
||||
t.integer "comments_count", default: 0
|
||||
t.datetime "confirmed_hide_at"
|
||||
t.integer "cached_anonymous_votes_total", default: 0
|
||||
@@ -278,6 +279,7 @@ ActiveRecord::Schema.define(version: 20170918231410) do
|
||||
add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree
|
||||
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
|
||||
add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree
|
||||
add_index "debates", ["description"], name: "index_debates_on_description", using: :btree
|
||||
add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree
|
||||
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
|
||||
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
|
||||
@@ -784,6 +786,7 @@ ActiveRecord::Schema.define(version: 20170918231410) do
|
||||
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
|
||||
add_index "proposals", ["community_id"], name: "index_proposals_on_community_id", using: :btree
|
||||
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
|
||||
add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree
|
||||
add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
|
||||
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
|
||||
add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree
|
||||
|
||||
@@ -318,6 +318,11 @@ FactoryGirl.define do
|
||||
feasibility "feasible"
|
||||
valuation_finished true
|
||||
end
|
||||
|
||||
trait :with_descriptive_image do
|
||||
image { File.new("spec/fixtures/files/logo_header.jpg") }
|
||||
image_description "Lorem ipsum dolor sit amet"
|
||||
end
|
||||
end
|
||||
|
||||
factory :budget_ballot, class: 'Budget::Ballot' do
|
||||
|
||||
@@ -30,27 +30,61 @@ describe Budget::Investment do
|
||||
end
|
||||
|
||||
describe "#image" do
|
||||
let(:investment_with_image) { build(:budget_investment, :with_descriptive_image) }
|
||||
|
||||
describe "extesion" do
|
||||
it "should be valid" do
|
||||
expect(investment_with_image).to be_valid
|
||||
end
|
||||
|
||||
describe "file extension" do
|
||||
it "should not be valid with '.png' extension" do
|
||||
investment.image = File.new("spec/fixtures/files/logo_header.png")
|
||||
investment_with_image.image = File.new("spec/fixtures/files/logo_header.png")
|
||||
|
||||
expect(investment).to_not be_valid
|
||||
expect(investment_with_image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid with '.gif' extension" do
|
||||
investment.image = File.new("spec/fixtures/files/logo_header.gif")
|
||||
investment_with_image.image = File.new("spec/fixtures/files/logo_header.gif")
|
||||
|
||||
expect(investment).to_not be_valid
|
||||
expect(investment_with_image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should be valid with '.jpg' extension" do
|
||||
investment.image = File.new("spec/fixtures/files/logo_header.jpg")
|
||||
investment_with_image.image = File.new("spec/fixtures/files/logo_header.jpg")
|
||||
|
||||
expect(investment).to be_valid
|
||||
expect(investment_with_image).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "description" do
|
||||
|
||||
it "should be valid when image and image_description are not defined" do
|
||||
investment_with_image.image = nil
|
||||
investment_with_image.image_description = nil
|
||||
|
||||
expect(investment_with_image).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid when correct image attached but no image description provided" do
|
||||
investment_with_image.image_description = ''
|
||||
|
||||
expect(investment_with_image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid when image description is too short" do
|
||||
investment_with_image.image_description = 'a'*3
|
||||
|
||||
expect(investment_with_image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid when image description is too long" do
|
||||
investment_with_image.image_description = 'a'*81
|
||||
|
||||
expect(investment_with_image).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "sanitizes description" do
|
||||
|
||||
Reference in New Issue
Block a user