diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index fabb77d28..ab20e76e3 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -75,7 +75,7 @@ class ProposalsController < ApplicationController private def proposal_params - params.require(:proposal).permit(:title, :question, :description, :external_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key) + params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key) end def load_featured_tags diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 6597b16e8..9e1b1daa6 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -12,7 +12,7 @@ class Proposal < ActiveRecord::Base validates :title, presence: true validates :question, presence: true - validates :description, presence: true + validates :summary, presence: true validates :author, presence: true validates :responsible_name, presence: true @@ -131,7 +131,6 @@ class Proposal < ActiveRecord::Base def validate_description_length validator = ActiveModel::Validations::LengthValidator.new( attributes: :description, - minimum: 10, maximum: Proposal.description_max_length) validator.validate(self) end diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index ab1c22057..b2941bd44 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -16,9 +16,10 @@
- <%= f.label :question, t("proposals.form.proposal_summary") %> + <%= f.label :summary, t("proposals.form.proposal_summary") %> <%= t("proposals.form.proposal_summary_note") %> - + <%= f.text_area :summary, rows: 4, maxlength: 200, label: false, + placeholder: t('proposals.form.proposal_summary') %>
diff --git a/app/views/proposals/_proposal.html.erb b/app/views/proposals/_proposal.html.erb index cba2523cc..21cb53f5b 100644 --- a/app/views/proposals/_proposal.html.erb +++ b/app/views/proposals/_proposal.html.erb @@ -14,7 +14,7 @@ <%= l proposal.created_at.to_date %>

- <%= link_to proposal.description, proposal %> + <%= link_to proposal.summary, proposal %>
<%= render "shared/tags", proposal: proposal, limit: 5 %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index a98ca1d69..e18b8ddd9 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -58,6 +58,8 @@
+
<%= @proposal.summary %>
+ <%= safe_html_with_links @proposal.description %> <% if @proposal.external_url.present? %> diff --git a/db/migrate/20150914173834_add_summary_to_proposals.rb b/db/migrate/20150914173834_add_summary_to_proposals.rb new file mode 100644 index 000000000..7ebe2df9c --- /dev/null +++ b/db/migrate/20150914173834_add_summary_to_proposals.rb @@ -0,0 +1,5 @@ +class AddSummaryToProposals < ActiveRecord::Migration + def change + add_column :proposals, :summary, :text, limit: 280 + end +end diff --git a/db/schema.rb b/db/schema.rb index 9add178d4..330444165 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150914114019) do +ActiveRecord::Schema.define(version: 20150914173834) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -206,6 +206,7 @@ ActiveRecord::Schema.define(version: 20150914114019) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "responsible_name", limit: 60 + t.text "summary" end create_table "settings", force: :cascade do |t| diff --git a/spec/factories.rb b/spec/factories.rb index ae6a15cab..cda9c01a8 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -114,6 +114,7 @@ FactoryGirl.define do factory :proposal do sequence(:title) { |n| "Proposal #{n} title" } + summary 'In summary, what we want is...' description 'Proposal description' question 'Proposal question' external_url 'http://external_documention.es' diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index d8a545a5d..a7c6bf70a 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -11,7 +11,7 @@ feature 'Proposals' do proposal.each do |proposal| within('#proposals') do expect(page).to have_content proposal.title - expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.description) + expect(page).to have_css("a[href='#{proposal_path(proposal)}']", text: proposal.summary) end end end @@ -59,6 +59,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: 'Help refugees' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: 'This is very important because...' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -70,6 +71,7 @@ feature 'Proposals' do expect(page).to have_content 'Proposal was successfully created.' expect(page).to have_content 'Help refugees' expect(page).to have_content '¿Would you like to give assistance to war refugees?' + expect(page).to have_content 'In summary, what we want is...' expect(page).to have_content 'This is very important because...' expect(page).to have_content 'http://rescue.org/refugees' expect(page).to have_content author.name @@ -83,6 +85,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: 'Help refugees' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: 'This is very important because...' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -105,6 +108,7 @@ feature 'Proposals' do fill_in 'proposal_title', with: 'Help refugees' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: 'This is very important because...' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_captcha', with: correct_captcha_text @@ -121,6 +125,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: "Great title" fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: 'Very important issue...' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -146,6 +151,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: "" fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: 'Very important issue...' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -178,6 +184,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: 'Testing an attack' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: '

This is

' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -200,6 +207,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: 'Testing auto link' fill_in 'proposal_question', with: 'Should I stay or should I go?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: '

This is a link www.example.org

' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' fill_in 'proposal_captcha', with: correct_captcha_text @@ -219,6 +227,7 @@ feature 'Proposals' do visit new_proposal_path fill_in 'proposal_title', with: 'Testing auto link' fill_in 'proposal_question', with: 'Should I stay or should I go?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: " click me http://example.org" fill_in 'proposal_responsible_name', with: 'Isabel Garcia' fill_in 'proposal_captcha', with: correct_captcha_text @@ -255,6 +264,7 @@ feature 'Proposals' do fill_in 'proposal_title', with: 'A test with enough characters' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in_ckeditor 'proposal_description', with: 'A description with enough characters' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -278,6 +288,7 @@ feature 'Proposals' do fill_in 'proposal_title', with: 'A test of dangerous strings' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' fill_in 'proposal_description', with: 'A description suitable for this test' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -331,6 +342,7 @@ feature 'Proposals' do fill_in 'proposal_title', with: "End child poverty" fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'Basically...' fill_in 'proposal_description', with: "Let's do something to end child poverty" fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_responsible_name', with: 'Isabel Garcia' @@ -339,6 +351,7 @@ feature 'Proposals' do click_button "Save changes" expect(page).to have_content "Proposal was successfully updated." + expect(page).to have_content "Basically..." expect(page).to have_content "End child poverty" expect(page).to have_content "Let's do something to end child poverty" end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 6c835bee8..fe2422173 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -22,12 +22,12 @@ describe Proposal do expect(proposal).to_not be_valid end - describe "#description" do - it "should be mandatory" do - proposal.description = nil - expect(proposal).to_not be_valid - end + it "should not be valid without a summary" do + proposal.summary = nil + expect(proposal).to_not be_valid + end + describe "#description" do it "should be sanitized" do proposal.description = "" proposal.valid?