- <%= image_tag investment.image.url(:large),
- title: investment.image_title,
- alt: investment.image_title %>
+ <%= image_tag investment.image_url(:large),
+ alt: investment.image.title %>
- <%= investment.image_title %>
+ <%= investment.image.title %>
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index 5070e27a7..27d9b10c5 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -219,6 +219,11 @@ en:
attributes:
max_per_day:
invalid: "You have reached the maximum number of private messages per day"
+ image:
+ attributes:
+ attachment:
+ min_image_width: "Image Width must be at least %{required_min_width}px"
+ min_image_height: "Image Height must be at least %{required_min_height}px"
poll/voter:
attributes:
document_number:
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index 238782276..a5ab18d9e 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -214,6 +214,11 @@ es:
attributes:
max_per_day:
invalid: "Has llegado al número máximo de mensajes privados por día"
+ image:
+ attributes:
+ attachment:
+ min_image_width: "La imagen debe tener al menos %{required_min_width}px de largo"
+ min_image_height: "La imagen debe tener al menos %{required_min_height}px de alto"
poll/voter:
attributes:
document_number:
diff --git a/config/routes.rb b/config/routes.rb
index 386a3fbf5..400c7bb7e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -36,6 +36,10 @@ Rails.application.routes.draw do
get '/welcome', to: 'welcome#welcome'
get '/cuentasegura', to: 'welcome#verification', as: :cuentasegura
+ concern :imageable do
+ resources :images
+ end
+
resources :debates do
member do
post :vote
@@ -77,7 +81,7 @@ Rails.application.routes.draw do
resources :budgets, only: [:show, :index] do
resources :groups, controller: "budgets/groups", only: [:show]
- resources :investments, controller: "budgets/investments", only: [:index, :new, :create, :show, :destroy] do
+ resources :investments, controller: "budgets/investments", only: [:index, :new, :create, :show, :destroy], concerns: :imageable do
member do
post :vote
get :edit_image
@@ -229,7 +233,7 @@ Rails.application.routes.draw do
end
end
- resources :budget_investments, only: [:index, :show, :edit, :update] do
+ resources :budget_investments, only: [:index, :show, :edit, :update], concerns: :imageable do
resources :budget_investment_milestones
member { patch :toggle_selection }
end
diff --git a/spec/factories.rb b/spec/factories.rb
index 4f44ccb32..fc4e41310 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -320,11 +320,15 @@ FactoryGirl.define do
end
trait :with_descriptive_image do
- image { File.new("spec/fixtures/files/clippy.jpg") }
- image_title "Lorem ipsum dolor sit amet"
+ association :image, factory: :image
end
end
+ factory :image, class: 'Image' do
+ attachment { File.new("spec/fixtures/files/clippy.jpg") }
+ title "Lorem ipsum dolor sit amet"
+ end
+
factory :budget_ballot, class: 'Budget::Ballot' do
association :user, factory: :user
budget
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index 5fbba0e59..3633f4b7f 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -29,8 +29,8 @@ feature 'Budget Investments' do
end
scenario 'Index should show investment descriptive image only when is defined' do
- investment = create(:budget_investment, heading: heading)
- investment_with_image = create(:budget_investment, :with_descriptive_image, heading: heading)
+ investment = FactoryGirl.create(:budget_investment, heading: heading)
+ investment_with_image = FactoryGirl.create(:budget_investment, :with_descriptive_image, heading: heading)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -39,7 +39,7 @@ feature 'Budget Investments' do
end
within("#budget_investment_#{investment_with_image.id}") do
- expect(page).to have_css("picture img[alt='#{investment_with_image.image_title}'][title='#{investment_with_image.image_title}']")
+ expect(page).to have_css("picture img[alt='#{investment_with_image.image.title}']")
end
end
@@ -377,7 +377,7 @@ feature 'Budget Investments' do
visit budget_investment_path(budget_id: budget.id, id: investment_with_image.id)
- expect(page).to have_css("img[alt='#{investment_with_image.image_title}'][title='#{investment_with_image.image_title}']")
+ expect(page).to have_css("img[alt='#{investment_with_image.image.title}']")
end
scenario "Show back link contains heading id" do
diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb
index 5f0a519d9..8e78bb88d 100644
--- a/spec/models/budget/investment_spec.rb
+++ b/spec/models/budget/investment_spec.rb
@@ -29,7 +29,7 @@ describe Budget::Investment do
end
end
- describe "#image and #image_title" do
+ describe "#image and #image_title", :investment_image do
let(:investment_with_image) { build(:budget_investment, :with_descriptive_image) }
it "should be valid" do