Skip to content
This repository has been archived by the owner on Jan 30, 2018. It is now read-only.

Commit

Permalink
Add factories_spec.rb and Rake commands
Browse files Browse the repository at this point in the history
* Remove one factory which created an invalid instance
* Add invitee for Event factory, making it valid
* Change test to 'build' to create associations
* Update failing tests
  • Loading branch information
Adarsh Pandit committed Sep 11, 2012
1 parent 55a78a5 commit eb9f9cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
12 changes: 9 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
# for example lib/tasks/capistrano.rake, and they will automatically be
# available to Rake.

require File.expand_path('../config/application', __FILE__)

SchedDo::Application.load_tasks

if defined?(RSpec)
desc "Run acceptance specs"
desc 'Run factory specs'
RSpec::Core::RakeTask.new(:factory_specs) do |t|
t.pattern = './spec/factories_spec.rb'
end

desc 'Run acceptance specs'
RSpec::Core::RakeTask.new(:acceptance) do |t|
t.pattern = 'spec/acceptance/**/*.feature'
end
end


task spec: :factory_specs
task(:default).clear
task :default => [:spec, :acceptance, 'spec:javascripts']
7 changes: 2 additions & 5 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

factory :invitation do
event
association :invitee, factory: :user
invitee_type 'User'

factory :invitation_with_user do
association :invitee, factory: :user
Expand All @@ -79,10 +81,5 @@
association :invitee, factory: :guest
invitee_type 'Guest'
end

factory :invitation_with_guest_without_name do
association :invitee, factory: :guest, name: nil
invitee_type 'Guest'
end
end
end
9 changes: 9 additions & 0 deletions spec/factories_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

FactoryGirl.factories.map(&:name).each do |factory_name|
describe "The #{factory_name} factory" do
it 'is valid' do
create(factory_name).should be_valid
end
end
end
10 changes: 6 additions & 4 deletions spec/models/invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it 'should notify a group after creation' do
group = create(:group)
group.stubs(:notify)
invitation = build(:invitation, invitee: group)
invitation = build(:invitation_with_group, invitee: group)

invitation.save

Expand All @@ -66,14 +66,16 @@
end

it 'returns an email if the invitee has no name' do
invitation = build_stubbed(:invitation_with_guest_without_name)
invitation = build_stubbed(:invitation_with_guest)
guest = invitation.invitee
guest.name = nil

invitation.name_or_email.should == invitation.invitee.email
invitation.invitee.name.should be_nil
end

it 'returns nil if there is no invitee' do
invitation = build_stubbed(:invitation)
invitation = build_stubbed(:invitation, invitee: nil)

invitation.name_or_email.should == nil
end
Expand Down Expand Up @@ -121,7 +123,7 @@
end

it 'should return nil if there is no invitee' do
invitation = build_stubbed(:invitation)
invitation = build_stubbed(:invitation, invitee: nil)

invitation.yammer_user_id.should == nil
end
Expand Down

0 comments on commit eb9f9cc

Please sign in to comment.