From fdd5b6cb95eb3175a3fa885099d910eb02fdf6c6 Mon Sep 17 00:00:00 2001 From: Stella Date: Fri, 2 May 2014 21:33:43 +0300 Subject: [PATCH 1/9] Add 'edit button' in proposal show --- app/views/proposal/show.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index 02173839..0d9e83a1 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -6,6 +6,8 @@ %br %small = @event.subtitle + - if has_role?(current_user, "admin") + = link_to "Edit", edit_admin_conference_event_path(@conference.short_title, @event), :class => "btn btn-mini btn-primary pull-right" .row .col-md-3 %p From 1840a858b7430b394f9cccca780118dc3e846227 Mon Sep 17 00:00:00 2001 From: Stella Date: Fri, 2 May 2014 21:40:42 +0300 Subject: [PATCH 2/9] button to link to schedule --- app/views/proposal/show.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index 0d9e83a1..82689111 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -6,6 +6,7 @@ %br %small = @event.subtitle + = link_to "Schedule", conference_schedule_path(@conference.short_title), :class =>"btn btn-success pull-right" - if has_role?(current_user, "admin") = link_to "Edit", edit_admin_conference_event_path(@conference.short_title, @event), :class => "btn btn-mini btn-primary pull-right" .row From c5c240888c1fcd900b8fda75c0fc17c4d2460937 Mon Sep 17 00:00:00 2001 From: Stella Date: Fri, 2 May 2014 21:58:55 +0300 Subject: [PATCH 3/9] Add details of proposal in show page --- app/views/proposal/show.html.haml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index 82689111..c5d45738 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -16,6 +16,12 @@ %dl %dt Date: %dd= @event.start_time.strftime("%Y %B %e %H:%M") if @event.start_time + %dt Duration: + %dd= show_time(@event.event_type.length) + %dt Room: + %dd + - if @event.room_id + = @event.room.name %dt Conference: %dd= @event.conference.title %dt Language: @@ -25,6 +31,11 @@ - if @event.track_id %span.label{:style =>"background-color: #{@event.track.color};"} = @event.track.name + %dt Difficulty: + %dd + - if @event.difficulty_level_id + %span.label{:style =>"background-color: #{@event.difficulty_level.color};"} + = @event.difficulty_level.title .col-md-9 .row .col-md-12 From 8be57503823c9e10708cf27b2808b03931c09407 Mon Sep 17 00:00:00 2001 From: Stella Date: Fri, 2 May 2014 22:52:11 +0300 Subject: [PATCH 4/9] show speaker's email --- app/views/proposal/show.html.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index c5d45738..5894da25 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -56,6 +56,9 @@ %h3 by = @speaker.public_name + ( + = @speaker.email + ) - if @speaker.company? %br %span.muted From b4425128e6b5f6122ada267a0cfec46f25afdd63 Mon Sep 17 00:00:00 2001 From: Stella Date: Fri, 2 May 2014 22:52:58 +0300 Subject: [PATCH 5/9] Mention if registration is required --- app/views/proposal/show.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index 5894da25..9f974ede 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -36,6 +36,8 @@ - if @event.difficulty_level_id %span.label{:style =>"background-color: #{@event.difficulty_level.color};"} = @event.difficulty_level.title + - if @event.require_registration + = link_to "Registration required!", register_conference_path(@conference.short_title), :class => "btn btn-xs btn-warning" .col-md-9 .row .col-md-12 From aff37e8fb1857748bf3457c7b3d1502d3bcfdb13 Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Fri, 9 May 2014 14:14:21 +0200 Subject: [PATCH 6/9] Conference Model tests --- Gemfile | 1 + Gemfile.lock | 7 +++ spec/models/conference_spec.rb | 91 ++++++++++++++++++++++++++-------- 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 2c8fd572..e49a4c5b 100644 --- a/Gemfile +++ b/Gemfile @@ -76,6 +76,7 @@ group :development, :test do gem 'rspec', '>= 3.0.0.beta' gem 'rspec-rails', '>= 3.0.0.beta' gem 'capybara' + gem 'shoulda' end # FIXME: We should use http://weblog.rubyonrails.org/2012/3/21/strong-parameters/ diff --git a/Gemfile.lock b/Gemfile.lock index 58e6d2a8..a8a5bce1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -248,6 +248,12 @@ GEM sass (~> 3.2.0) sprockets (~> 2.8, <= 2.11.0) sprockets-rails (~> 2.0) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.1) + shoulda-matchers (2.6.1) + activesupport (>= 3.0.0) simplecov (0.8.2) docile (~> 1.1.0) multi_json @@ -329,6 +335,7 @@ DEPENDENCIES rspec (>= 3.0.0.beta) rspec-rails (>= 3.0.0.beta) sass-rails (>= 4.0.2) + shoulda spring-commands-rspec sqlite3 transitions diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 5722b4a9..e1d2093f 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1,72 +1,121 @@ +#!/bin/env ruby +# encoding: utf-8 require 'spec_helper' describe Conference do let(:subject) { create(:conference) } - describe "#registration_open?" do + describe '#registration_open?' do - context "closed registration" do + context 'closed registration' do - it "#registration_open? is false" do + it '#registration_open? is false' do expect(subject.registration_open?).to be false end - end - context "open registration" do + context 'open registration' do before do subject.registration_start_date = Date.today - 1 subject.registration_end_date = Date.today + 7 end - it "#registration_open? is true" do + it '#registration_open? is true' do expect(subject.registration_open?).to be true end - end - end - describe "#cfp_open?" do + describe '#cfp_open?' do - context "closed cfp" do + context 'closed cfp' do - it "#cfp_open? is false" do + it '#cfp_open? is false' do expect(subject.cfp_open?).to be false end end - context "open cfp" do + context 'open cfp' do before do subject.call_for_papers = create(:call_for_papers) end - it "#registration_open? is true" do + it '#registration_open? is true' do expect(subject.cfp_open?).to be true end - end - end - describe "#user_registered?" do + describe '#user_registered?' do let(:user) { create(:user) } - context "user not registered" do - it "#user_registered? is false" do + context 'user not registered' do + it '#user_registered? is false' do expect(subject.user_registered? user).to be false end end - context "user registered" do + context 'user registered' do pending "isn't tested yet" end - end - + + describe 'validations' do + + it 'has a valid factory' do + expect(build(:conference)).to be_valid + end + + it 'is not valid without a title' do + should validate_presence_of(:title) + end + + it 'is not valid without a short title' do + should validate_presence_of(:short_title) + end + + it 'is not valid without a social tag' do + should validate_presence_of(:social_tag) + end + + it 'is not valid without a start date' do + should validate_presence_of(:start_date) + end + + it 'is not valid without an end date' do + should validate_presence_of(:end_date) + end + + it 'is not valid with a duplicate short title' do + should validate_uniqueness_of(:short_title) + end + + it 'is valid with a short title that contains a-zA-Z0-9_-' do + should allow_value('abc_xyz-ABC-XYZ-012_89').for(:short_title) + end + + it 'is not valid with a short title that contains special characters' do + should_not allow_value('&%§!?äÄüÜ/()').for(:short_title) + end + + describe 'before create callbacks' do + + it 'has an email setting after creation' do + expect(subject.email_settings).not_to be_nil + end + + it 'has a venue after creation' do + expect(subject.venue).not_to be_nil + end + + it 'has a guid after creation' do + expect(subject.guid).not_to be_nil + end + end + end end From 6e946dbb1daf9e52f84f72ba24d7d96d28f64528 Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Mon, 12 May 2014 13:20:28 +0200 Subject: [PATCH 7/9] Maintain schema --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0df96be7..6c71f631 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,9 @@ require 'rspec/rails' # run twice. It is recommended that you do not name files matching this glob to # end with _spec.rb. You can configure this pattern with with the --pattern # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. + +ActiveRecord::Migration.maintain_test_schema! + Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| From e19aef91d09b1921428c4fcda281e9c7d5bc72ec Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Mon, 12 May 2014 14:29:15 +0200 Subject: [PATCH 8/9] Add docs back --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c71f631..bec05b48 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,8 @@ require 'rspec/rails' # end with _spec.rb. You can configure this pattern with with the --pattern # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } From 27f35a49c630c39c74d9b26dfcfd4af90bd92ec4 Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Mon, 12 May 2014 14:38:55 +0200 Subject: [PATCH 9/9] Fix create conference form - adds HTML 5 validations --- .../admin/conference_controller.rb | 9 +++++--- app/views/admin/conference/new.html.haml | 23 +++++++++++-------- app/views/layouts/application.html.haml | 2 +- config/initializers/formtastic.rb | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/conference_controller.rb b/app/controllers/admin/conference_controller.rb index 0027ff77..571d14ab 100644 --- a/app/controllers/admin/conference_controller.rb +++ b/app/controllers/admin/conference_controller.rb @@ -15,10 +15,13 @@ class Admin::ConferenceController < ApplicationController def create @conference = Conference.new(params[:conference]) - if @conference.save - redirect_to(admin_conference_path(:id => @conference.short_title), :notice => 'Conference was successfully created.') + if @conference.valid? + @conference.save + redirect_to(admin_conference_path(id: @conference.short_title), + notice: 'Conference was successfully created.') else - render :action => "new" + redirect_to(new_admin_conference_path, + flash: { error: @conference.errors.full_messages.join('! ') }) end end diff --git a/app/views/admin/conference/new.html.haml b/app/views/admin/conference/new.html.haml index 1b78f27d..f77d9d0b 100644 --- a/app/views/admin/conference/new.html.haml +++ b/app/views/admin/conference/new.html.haml @@ -1,14 +1,17 @@ .row .col-md-6.col-md-offset-3 = semantic_form_for(@conference, :url => admin_conference_index_path) do |f| - = f.inputs "Basic Information" do - = f.input :title, :hint => "The name of your conference as it shall appear throughout the site. Example: 'OpenSUSE Conference 2013'" - = f.input :short_title, :hint => "A short and unique handle for your conference, using only lower-case letters, numbers and underscores. This will be used to identify your conference in URLs etc. Example: 'froscon2011'" - = f.input :social_tag, :hint => "The hashtag you'll use on Twitter and Google+. Don't include the '#' sign!'" - = f.input :contact_email, :hint => "Contact email address for your conference. Will be used as reply-to address in emails sent out by the system." - = f.inputs "Scheduling" do - = f.input :timezone, :as => :time_zone, :hint => "Please select in what time zone your conference will take place." - = f.input :start_date, :as => :string, :input_html => { :id => "conference-start-datepicker", :readonly => "readonly" } - = f.input :end_date, :as => :string, :input_html => { :id => "conference-end-datepicker", :readonly => "readonly" } + = f.inputs 'Basic Information' do + = f.input :title, hint: "The name of your conference as it shall appear throughout the site. Example: 'OpenSUSE Conference 2013'", + input_html: { required: 'required' } + = f.input :short_title, hint: "A short and unique handle for your conference, using only lower-case letters, numbers and underscores. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", + input_html: { required: 'required' } + = f.input :social_tag, hint: "The hashtag you'll use on Twitter and Google+. Don't include the '#' sign!'", + input_html: { required: 'required' } + = f.input :contact_email, hint: 'Contact email address for your conference. Will be used as reply-to address in emails sent out by the system.' + = f.inputs 'Scheduling' do + = f.input :timezone, as: :time_zone, hint: 'Please select in what time zone your conference will take place.' + = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', readonly: 'readonly', required: 'required' } + = f.input :end_date, as: :string, input_html: { id: 'conference-end-datepicker', readonly: 'readonly', required: 'required' } = f.actions do - = f.action :submit, :button_html => {:class => "btn btn-success pull-right"} + = f.action :submit, button_html: {class: 'btn btn-success pull-right'} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index c844c4a3..e9e9e0af 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -1,4 +1,4 @@ -!!! +%html{:xmlns => "http://www.w3.org/1999/html"} %html %head %meta{:charset => "utf-8"} diff --git a/config/initializers/formtastic.rb b/config/initializers/formtastic.rb index 69eaae95..b676d4a0 100644 --- a/config/initializers/formtastic.rb +++ b/config/initializers/formtastic.rb @@ -73,7 +73,7 @@ Formtastic::FormBuilder.required_string = "(required)" # You can opt-in to new HTML5 browser validations (for things like email and url inputs) by setting # this to false. Doing so will add a `novalidate` attribute to the `
` tag. # See http://diveintohtml5.org/forms.html#validation for more info. -# Formtastic::FormBuilder.perform_browser_validations = true +Formtastic::FormBuilder.perform_browser_validations = true # Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder FormtasticBootstrap::FormBuilder.default_inline_hint_class = FormtasticBootstrap::FormBuilder.default_block_hint_class