Skip to content

Commit

Permalink
add shoulda gem and more model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manno committed Sep 13, 2015
1 parent 6536bdb commit dc9c1c2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -253,6 +259,7 @@ DEPENDENCIES
redcarpet
ri_cal
sass-rails (~> 5.0)
shoulda
simple_form
sqlite3
sucker_punch
Expand Down
28 changes: 23 additions & 5 deletions test/unit/conference_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 27 additions & 7 deletions test/unit/event_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/unit/person_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit dc9c1c2

Please sign in to comment.