Merge branch 'master' into update-dependencies

This commit is contained in:
Juanjo Bazán
2017-03-31 11:50:55 +02:00
committed by GitHub
9 changed files with 80 additions and 8 deletions

View File

@@ -129,16 +129,16 @@ module CommentableActions
when '4'
1.year.ago
else
Date.parse(params[:advanced_search][:date_min]) rescue nil
Date.parse(params[:advanced_search][:date_min]) rescue 100.years.ago
end
end
def search_finish_date
params[:advanced_search][:date_max].try(:to_date) || Date.today
(params[:advanced_search][:date_max].to_date rescue Date.today) || Date.today
end
def search_date_range
search_start_date.beginning_of_day..search_finish_date.end_of_day
[100.years.ago, search_start_date].max.beginning_of_day..[search_finish_date, Date.today].min.end_of_day
end
def set_search_order

View File

@@ -25,6 +25,7 @@ class Budget
validates :description, presence: true
validates :heading_id, presence: true
validates_presence_of :unfeasibility_explanation, if: :unfeasibility_explanation_required?
validates_presence_of :price, if: :price_required?
validates :title, length: { in: 4..Budget::Investment.title_max_length }
validates :description, length: { maximum: Budget::Investment.description_max_length }
@@ -136,6 +137,10 @@ class Budget
unfeasible? && valuation_finished?
end
def price_required?
feasible? && valuation_finished?
end
def unfeasible_email_pending?
unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished?
end

View File

@@ -103,7 +103,7 @@
<div class="social-share-full">
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
<a href="whatsapp://send?text=<%= investment.title %> <%= budget_investment_url(budget_id: investment.budget_id, id: investment.id) %>" data-action="share/whatsapp/share">
<a href="whatsapp://send?text=<%= investment.title.gsub(/\s/, '&nbsp;') %>&nbsp;<%= budget_investment_url(budget_id: investment.budget_id, id: investment.id) %>" data-action="share/whatsapp/share">
<span class="icon-whatsapp whatsapp"></span>
<span class="sr-only"><%= t("social.whatsapp") %></span>
</a>

View File

@@ -53,7 +53,7 @@
<div class="social-share-full">
<%= social_share_button_tag("#{@debate.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
<a href="whatsapp://send?text=<%= @debate.title %> <%= debate_url(@debate) %>" data-action="share/whatsapp/share">
<a href="whatsapp://send?text=<%= @debate.title.gsub(/\s/, '&nbsp;') %>&nbsp;<%= debate_url(@debate) %>" data-action="share/whatsapp/share">
<span class="icon-whatsapp whatsapp"></span>
<span class="sr-only"><%= t("social.whatsapp") %></span>
</a>

View File

@@ -126,7 +126,7 @@
<div class="social-share-full">
<%= social_share_button_tag("#{@proposal.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
<a href="whatsapp://send?text=<%= @proposal.title %> <%= proposal_url(@proposal) %>" data-action="share/whatsapp/share">
<a href="whatsapp://send?text=<%= @proposal.title.gsub(/\s/, '&nbsp;') %>&nbsp;<%= proposal_url(@proposal) %>" data-action="share/whatsapp/share">
<span class="icon-whatsapp whatsapp"></span>
<span class="sr-only"><%= t("social.whatsapp") %></span>
</a>

View File

@@ -45,7 +45,7 @@
<div class="social-share-full">
<%= social_share_button_tag("#{@spending_proposal.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
<a href="whatsapp://send?text=<%= @spending_proposal.title %> <%= spending_proposal_url(@spending_proposal) %>" data-action="share/whatsapp/share">
<a href="whatsapp://send?text=<%= @spending_proposal.title.gsub(/\s/, '&nbsp;') %>&nbsp;<%= spending_proposal_url(@spending_proposal) %>" data-action="share/whatsapp/share">
<span class="icon-whatsapp whatsapp"></span>
<span class="sr-only"><%= t("social.whatsapp") %></span>
</a>

View File

@@ -640,6 +640,28 @@ feature 'Debates' do
end
end
scenario "Search by custom invalid date range", :js do
debate1 = create(:debate, created_at: 2.years.ago)
debate2 = create(:debate, created_at: 3.days.ago)
debate3 = create(:debate, created_at: 9.days.ago)
visit debates_path
click_link "Advanced search"
select "Customized", from: "js-advanced-search-date-min"
fill_in "advanced_search_date_min", with: "9"
fill_in "advanced_search_date_max", with: "444444444"
click_button "Filter"
within("#debates") do
expect(page).to have_css('.debate', count: 3)
expect(page).to have_content(debate1.title)
expect(page).to have_content(debate2.title)
expect(page).to have_content(debate3.title)
end
end
scenario "Search by multiple filters", :js do
ana = create :user, official_level: 1
john = create :user, official_level: 1

View File

@@ -980,6 +980,28 @@ feature 'Proposals' do
end
end
scenario "Search by custom invalid date range", :js do
proposal1 = create(:proposal, created_at: 2.days.ago)
proposal2 = create(:proposal, created_at: 3.days.ago)
proposal3 = create(:proposal, created_at: 9.days.ago)
visit proposals_path
click_link "Advanced search"
select "Customized", from: "js-advanced-search-date-min"
fill_in "advanced_search_date_min", with: 4000.years.ago
fill_in "advanced_search_date_max", with: "wrong date"
click_button "Filter"
expect(page).to have_content("There are 3 citizen proposals")
within("#proposals") do
expect(page).to have_content(proposal1.title)
expect(page).to have_content(proposal2.title)
expect(page).to have_content(proposal3.title)
end
end
scenario "Search by multiple filters", :js do
ana = create :user, official_level: 1
john = create :user, official_level: 1

View File

@@ -54,7 +54,7 @@ describe Budget::Investment do
expect(investment.group_id).to eq group_2.id
end
describe "#unfeasibility_explanation" do
describe "#unfeasibility_explanation blank" do
it "should be valid if valuation not finished" do
investment.unfeasibility_explanation = ""
investment.valuation_finished = false
@@ -76,6 +76,29 @@ describe Budget::Investment do
end
end
describe "#price blank" do
it "should be valid if valuation not finished" do
investment.price = ""
investment.valuation_finished = false
expect(investment).to be_valid
end
it "should be valid if valuation finished and unfeasible" do
investment.price = ""
investment.unfeasibility_explanation = "reason"
investment.feasibility = "unfeasible"
investment.valuation_finished = true
expect(investment).to be_valid
end
it "should not be valid if valuation finished and feasible" do
investment.price = ""
investment.feasibility = "feasible"
investment.valuation_finished = true
expect(investment).to_not be_valid
end
end
describe "#code" do
let(:investment) { create(:budget_investment) }