Commit b2dab4e4 authored by Alexandre Friquet's avatar Alexandre Friquet

Admin can set season birthdate on settings: refs #89.

parent 679fe9c9
......@@ -58,6 +58,7 @@ gem 'fitvidsjs_rails'
gem 'font-awesome-rails'
gem 'jquery-minicolors-rails'
gem 'prettyphoto-rails'
gem 'validates_timeliness', '~> 5.0.0.alpha3'
group :development, :test do
gem "sqlite3"
......
......@@ -349,11 +349,14 @@ GEM
thread_safe (0.3.6)
tilt (2.0.8)
timecop (0.8.1)
timeliness (0.3.8)
truncate_html (0.9.3)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (3.2.0)
execjs (>= 0.3.0, < 3)
validates_timeliness (5.0.0.alpha3)
timeliness (~> 0.3.8)
vcr (2.9.3)
web-console (3.5.1)
actionview (>= 5.0)
......@@ -425,6 +428,7 @@ DEPENDENCIES
timecop (~> 0.8.0)
truncate_html
uglifier
validates_timeliness (~> 5.0.0.alpha3)
vcr (~> 2.9.3)
web-console
webmock (~> 1.17.4)
......
......@@ -54,7 +54,7 @@ class SettingsController < ApplicationController
def settings_params
params.require(:settings).permit(:contact_email, :gcal_pass, :gcal_user, :home_message, :motto, :title,
:site_logo, :motto_logo, :newsletters_title, :contact_message,
:site_logo, :motto_logo, :newsletters_title, :contact_message, :season_birthdate,
:main_color, :secondary_color, :h1_color, :h2_color,
:mono_activity_collaborating_price, :mono_activity_standard_price,
:multi_activities_collaborating_price, :multi_activities_standard_price,
......
......@@ -24,6 +24,10 @@ class Season
FIRST_MONTH = 8
FIRST_DAY = 15
def self.default_birthdate
Date.new(1970,FIRST_MONTH, FIRST_DAY)
end
def initialize(date)
year = (date < Date.new(date.year, FIRST_MONTH, FIRST_DAY) ? date.year-1 : date.year)
@begining = Date.new(year, FIRST_MONTH, FIRST_DAY)
......
......@@ -36,8 +36,11 @@ class Website < ApplicationRecord
attr_accessor :_destroy_site_logo, :_destroy_motto_logo
validates :contact_email, email_format: true, allow_blank: true
validates_attachment_size :site_logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo", :if => Proc.new { |file| !file.site_logo_file_name.blank? }
do_not_validate_attachment_file_type :site_logo
validates_attachment_size :motto_logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo", :if => Proc.new { |file| !file.site_logo_file_name.blank? }
do_not_validate_attachment_file_type :motto_logo
validates_date :season_birthdate, allow_blank: true
end
......@@ -34,6 +34,7 @@
<%= f.input :title %>
<%= f.input :motto %>
<%= f.input :home_message %>
<%= f.input :season_birthdate, default: Season.default_birthdate, discard_year: true %>
<% if @settings.site_logo.file? %>
<%= image_tag @settings.site_logo.url(:standard) %>
<div>
......
ValidatesTimeliness.setup do |config|
config.enable_multiparameter_extension!
config.enable_date_time_select_extension!
end
......@@ -221,6 +221,7 @@ fr:
even: "doit être pair"
taken: "n'est pas disponible"
record_invalid: "La validation a échoué : %{errors}"
invalid_date: "n'est pas une date valide"
template: &errors_template
header:
......
......@@ -185,6 +185,7 @@ fr:
mono_activity_standard_price: "Structure non partenaire"
multi_activities_collaborating_price: "Structure partenaire"
multi_activities_standard_price: "Structure non partenaire"
season_birthdate: "Changement de saison"
newsletter:
title: "Intitulé"
published: "Publiée"
......
class AddSeasonBirthdateToWebsites < ActiveRecord::Migration[5.1]
def change
add_column :websites, :season_birthdate, :date
end
end
......@@ -32,7 +32,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171211133706) do
ActiveRecord::Schema.define(version: 20180913142206) do
create_table "activities", force: :cascade do |t|
t.string "title", limit: 255
......@@ -400,6 +400,7 @@ ActiveRecord::Schema.define(version: 20171211133706) do
t.decimal "mono_activity_standard_price", precision: 5, scale: 2
t.decimal "multi_activities_collaborating_price", precision: 5, scale: 2
t.decimal "multi_activities_standard_price", precision: 5, scale: 2
t.date "season_birthdate"
end
end
......@@ -72,6 +72,28 @@ feature "Manage Settings" do
end
end
scenario "I can set the season switch day and month" do
day_select = "settings_season_birthdate_3i"
month_select = "settings_season_birthdate_2i"
visit edit_settings_path
expect(page).to have_field(day_select, with: "15")
expect(page).to have_field(month_select, with: "8")
within "form#edit_settings" do
select "1", from: day_select
select "septembre", from: month_select
click_button "Mettre à jour"
end
expect(current_path).to eq(edit_settings_path)
expect(page).to have_content "Les paramètres ont bien été mis à jour"
within "section#content" do
expect(page).to have_field(day_select, with: "1")
expect(page).to have_field(month_select, with: "9")
end
end
context "regarding images" do
scenario "I can provide a site logo" do
visit root_path
......
......@@ -31,5 +31,23 @@ describe Website do
it { is_expected.to allow_value("contact-all@net.example.com").for(:contact_email) }
it { is_expected.not_to allow_value("contact").for(:contact_email) }
it { is_expected.not_to allow_value("contact@example").for(:contact_email) }
describe "regarding season birthdate" do
it "validates the date is correct" do
# Only check one value, the purpose is not to
# test again the validates_timeliness gem ;)
# Given
settings = build :website
birthdate_attributes = {
"season_birthdate(3i)": "31",
"season_birthdate(2i)": "2",
"season_birthdate(1i)": "1970"
}
# When
settings.assign_attributes(birthdate_attributes)
# Then
expect(settings).not_to be_valid
end
end
end
end
\ No newline at end of file
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment