Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add factories_spec.rb and Rake commands

* 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...
commit eb9f9cc6565f9e0ec3901917c39ce4f1867e051e 1 parent 55a78a5
Adarsh Pandit adarsh authored
12 Rakefile
... ... @@ -1,18 +1,24 @@
1 1 #!/usr/bin/env rake
2 2 # Add your own tasks in files placed in lib/tasks ending in .rake,
3   -# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
  3 +# for example lib/tasks/capistrano.rake, and they will automatically be
  4 +# available to Rake.
4 5
5 6 require File.expand_path('../config/application', __FILE__)
6 7
7 8 SchedDo::Application.load_tasks
8 9
9 10 if defined?(RSpec)
10   - desc "Run acceptance specs"
  11 + desc 'Run factory specs'
  12 + RSpec::Core::RakeTask.new(:factory_specs) do |t|
  13 + t.pattern = './spec/factories_spec.rb'
  14 + end
  15 +
  16 + desc 'Run acceptance specs'
11 17 RSpec::Core::RakeTask.new(:acceptance) do |t|
12 18 t.pattern = 'spec/acceptance/**/*.feature'
13 19 end
14 20 end
15 21
16   -
  22 +task spec: :factory_specs
17 23 task(:default).clear
18 24 task :default => [:spec, :acceptance, 'spec:javascripts']
7 spec/factories.rb
@@ -64,6 +64,8 @@
64 64
65 65 factory :invitation do
66 66 event
  67 + association :invitee, factory: :user
  68 + invitee_type 'User'
67 69
68 70 factory :invitation_with_user do
69 71 association :invitee, factory: :user
@@ -79,10 +81,5 @@
79 81 association :invitee, factory: :guest
80 82 invitee_type 'Guest'
81 83 end
82   -
83   - factory :invitation_with_guest_without_name do
84   - association :invitee, factory: :guest, name: nil
85   - invitee_type 'Guest'
86   - end
87 84 end
88 85 end
9 spec/factories_spec.rb
... ... @@ -0,0 +1,9 @@
  1 +require 'spec_helper'
  2 +
  3 +FactoryGirl.factories.map(&:name).each do |factory_name|
  4 + describe "The #{factory_name} factory" do
  5 + it 'is valid' do
  6 + create(factory_name).should be_valid
  7 + end
  8 + end
  9 +end
10 spec/models/invitation_spec.rb
@@ -40,7 +40,7 @@
40 40 it 'should notify a group after creation' do
41 41 group = create(:group)
42 42 group.stubs(:notify)
43   - invitation = build(:invitation, invitee: group)
  43 + invitation = build(:invitation_with_group, invitee: group)
44 44
45 45 invitation.save
46 46
@@ -66,14 +66,16 @@
66 66 end
67 67
68 68 it 'returns an email if the invitee has no name' do
69   - invitation = build_stubbed(:invitation_with_guest_without_name)
  69 + invitation = build_stubbed(:invitation_with_guest)
  70 + guest = invitation.invitee
  71 + guest.name = nil
70 72
71 73 invitation.name_or_email.should == invitation.invitee.email
72 74 invitation.invitee.name.should be_nil
73 75 end
74 76
75 77 it 'returns nil if there is no invitee' do
76   - invitation = build_stubbed(:invitation)
  78 + invitation = build_stubbed(:invitation, invitee: nil)
77 79
78 80 invitation.name_or_email.should == nil
79 81 end
@@ -121,7 +123,7 @@
121 123 end
122 124
123 125 it 'should return nil if there is no invitee' do
124   - invitation = build_stubbed(:invitation)
  126 + invitation = build_stubbed(:invitation, invitee: nil)
125 127
126 128 invitation.yammer_user_id.should == nil
127 129 end

0 comments on commit eb9f9cc

Please sign in to comment.
Something went wrong with that request. Please try again.