Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
View
@@ -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 spec/factories.rb
View
@@ -64,6 +64,8 @@
factory :invitation do
event
+ association :invitee, factory: :user
+ invitee_type 'User'
factory :invitation_with_user do
association :invitee, factory: :user
@@ -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 spec/factories_spec.rb
View
@@ -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 spec/models/invitation_spec.rb
View
@@ -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
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.