From aff37e8fb1857748bf3457c7b3d1502d3bcfdb13 Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Fri, 9 May 2014 14:14:21 +0200 Subject: [PATCH] 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