From dc9c1c271686a5f48f9c22fb536efe60c7722644 Mon Sep 17 00:00:00 2001 From: Mario Manno Date: Sun, 13 Sep 2015 14:05:32 +0200 Subject: [PATCH] add shoulda gem and more model tests --- Gemfile | 3 ++- Gemfile.lock | 7 +++++++ test/unit/conference_test.rb | 28 +++++++++++++++++++++++----- test/unit/event_test.rb | 34 +++++++++++++++++++++++++++------- test/unit/person_test.rb | 12 ++++++++++++ 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index c4281fd66..3f7e0cebf 100644 --- a/Gemfile +++ b/Gemfile @@ -50,8 +50,9 @@ group :development, :test do end group :test do - gem 'factory_girl_rails', '~> 4.0' gem 'database_cleaner' + gem 'factory_girl_rails', '~> 4.0' + gem 'shoulda' end group :doc do diff --git a/Gemfile.lock b/Gemfile.lock index cb74cdcfb..bde0906be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -189,6 +189,12 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (~> 1.1) + 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.8.0) + activesupport (>= 3.0.0) simple_form (3.1.0) actionpack (~> 4.0) activemodel (~> 4.0) @@ -253,6 +259,7 @@ DEPENDENCIES redcarpet ri_cal sass-rails (~> 5.0) + shoulda simple_form sqlite3 sucker_punch diff --git a/test/unit/conference_test.rb b/test/unit/conference_test.rb index 2147f71a5..f960859f4 100644 --- a/test/unit/conference_test.rb +++ b/test/unit/conference_test.rb @@ -1,22 +1,40 @@ require 'test_helper' class ConferenceTest < ActiveSupport::TestCase + should have_many :availabilities + should have_many :conference_users + should have_many :days + should have_many :events + should have_many :languages + should have_many :notifications + should have_many :rooms + should have_many :tracks + should have_many :conference_exports + should have_one :call_for_participation + should have_one :ticket_server + should validate_presence_of :title + should validate_presence_of :acronym + should validate_presence_of :default_timeslots + should validate_presence_of :max_timeslots + should validate_presence_of :timeslot_duration + should validate_presence_of :timezone + test "current returns the newest conference" do - conferences = FactoryGirl.create_list(:conference, 3) + conferences = create_list(:conference, 3) assert_equal conferences.last.id, Conference.current.id end test "returns correct language codes" do - conference = FactoryGirl.create(:conference) - conference.languages << FactoryGirl.create(:english_language) - conference.languages << FactoryGirl.create(:german_language) + conference = create(:conference) + conference.languages << create(:english_language) + conference.languages << create(:german_language) assert_equal 2, conference.language_codes.size assert conference.language_codes.include? "en" assert conference.language_codes.include? "de" end test "returns the correct days" do - conference = FactoryGirl.create(:three_day_conference) + conference = create(:three_day_conference) assert_equal 3, conference.days.size assert_equal Date.today.since(3.days).since(10.hours), conference.days.last.start_date end diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb index 8e8eb95fb..92924a1bf 100644 --- a/test/unit/event_test.rb +++ b/test/unit/event_test.rb @@ -1,13 +1,33 @@ require 'test_helper' class EventTest < ActiveSupport::TestCase + should have_one :ticket + should have_many :conflicts_as_conflicting + should have_many :conflicts + should have_many :event_attachments + should have_many :event_feedbacks + should have_many :event_people + should have_many :event_ratings + should have_many :links + should have_many :people + should have_many :videos + should belong_to :conference + should belong_to :track + should belong_to :room + should accept_nested_attributes_for :event_people + should accept_nested_attributes_for :links + should accept_nested_attributes_for :event_attachments + should accept_nested_attributes_for :ticket + should validate_presence_of :title + should validate_presence_of :time_slots + setup do ActionMailer::Base.deliveries = [] - @notification = FactoryGirl.create(:notification) - @event = FactoryGirl.create(:event, conference: @notification.conference) - @speaker = FactoryGirl.create(:person) - FactoryGirl.create(:event_person, event: @event, person: @speaker, event_role: "speaker") - @coordinator = FactoryGirl.create(:person) + @notification = create(:notification) + @event = create(:event, conference: @notification.conference) + @speaker = create(:person) + create(:event_person, event: @event, person: @speaker, event_role: "speaker") + @coordinator = create(:person) end test "acceptance processing sends email if asked to" do @@ -18,7 +38,7 @@ class EventTest < ActiveSupport::TestCase test "acceptance processing sends german email if asked to" do @speaker.languages << Language.new(code: 'de') @event.conference.languages << Language.new(code: 'de') - notification = FactoryGirl.create(:notification, locale: 'de') + notification = create(:notification, locale: 'de') @notification.conference.notifications << notification @event.process_acceptance(send_mail: true) @@ -53,7 +73,7 @@ class EventTest < ActiveSupport::TestCase end test "correctly detects overlapping of events" do - other_event = FactoryGirl.create(:event) + other_event = create(:event) other_event.start_time = @event.start_time.ago(30.minutes) assert @event.overlap?(other_event) other_event.start_time = @event.start_time.ago(1.hour) diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index f33c600f6..dbce2ec57 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1,6 +1,18 @@ require 'test_helper' class PersonTest < ActiveSupport::TestCase + should validate_presence_of :public_name + should validate_presence_of :email + should have_many :availabilities + should have_many :event_people + should have_many :event_ratings + should have_many :events + should have_many :im_accounts + should have_many :languages + should have_many :links + should have_many :phone_numbers + should belong_to :user + test "#full_name" do person = build(:person) assert_equal "Fred Besen", person.full_name