* [gentoo-commits] proj/recruiting-webapp:master commit in: spec/
@ 2011-03-19 15:44 Petteri Räty
0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-03-19 15:44 UTC (permalink / raw
To: gentoo-commits
commit: ee550e2c44169f2004ec4345748fbba1ed7fc6f6
Author: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 12 20:00:20 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Mar 12 20:00:20 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/recruiting-webapp.git;a=commit;h=ee550e2c
Simplify factory sequence usage
Instead of creating separate sequences just use the inline block syntax
in cases where the sequence is only needed in one place.
---
spec/factories.rb | 48 ++++++++----------------------------------------
1 files changed, 8 insertions(+), 40 deletions(-)
diff --git a/spec/factories.rb b/spec/factories.rb
index 3ead1e1..5253103 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -1,54 +1,34 @@
- Factory.sequence :recruit do |n|
- "recruit-#{n}"
- end
-
- Factory.sequence :mentor do |n|
- "mentor-#{n}"
- end
-
- Factory.sequence :recruiter do |n|
- "recruiter-#{n}"
- end
-
- Factory.sequence :administrator do |n|
- "administrator-#{n}"
- end
-
# Creates a new mentor for recruit by default
Factory.define :recruit, :class => User do |u|
- u.name { Factory.next(:recruit) }
+ u.sequence(:name) { |n| "recruit-#{n}" }
u.email_address { |u| "#{u.name}@recruits.org" }
u.mentor { Factory(:mentor) }
end
Factory.define :mentor, :class => User do |u|
- u.name { Factory.next(:mentor) }
+ u.sequence(:name) { |n| "mentor-#{n}" }
u.email_address { |u| "#{u.name}@recruiters.org" }
u.role :mentor
u.nick { |u| u.name }
end
Factory.define :recruiter, :class => User do |u|
- u.name { Factory.next(:recruiter) }
+ u.sequence(:name) { |n| "recruiter-#{n}" }
u.email_address { |u| "#{u.name}@recruiters.org" }
u.role :recruiter
u.nick { |u| u.name }
end
Factory.define :administrator, :class => User do |u|
- u.name { Factory.next(:administrator) }
+ u.sequence(:name) { |n| "administrator-#{n}" }
u.email_address { |u| "#{u.name}@admins.org" }
u.role :recruiter
u.administrator true
u.nick { |u| u.name }
end
- Factory.sequence :category do |n|
- "category-#{n}"
- end
-
Factory.define :category do |q|
- q.name { Factory.next(:category) }
+ q.sequence(:name) { |n| "category-#{n}" }
end
Factory.define :question_category do |qc|
@@ -56,13 +36,9 @@
qc.association :category
end
- Factory.sequence :question do |n|
- "question-#{n}"
- end
-
# it'll belong to new category by default
Factory.define :question do |q|
- q.title { Factory.next(:question) }
+ q.sequence(:title) { |n| "question-#{n}" }
q.after_build { |q|
q.categories = [Factory.build :category]
}
@@ -91,14 +67,10 @@
q.category { Factory(:category) }
end
- Factory.sequence :comment do |n|
- "comment-#{n}"
- end
-
Factory.define :comment do |c|
c.answer { Factory(:answer) }
c.owner { |c| c.answer.owner.mentor }
- c.content { Factory.next(:comment) }
+ c.sequence(:content) { |n| "comment-#{n}" }
end
# create new recruit (being accepted) and mentor (accepting) by default
@@ -107,12 +79,8 @@
a.accepting_nick { Factory(:mentor).nick }
end
- Factory.sequence :question_group do |n|
- "question_group-#{n}"
- end
-
Factory.define :question_group do |c|
- c.name { Factory.next(:question_group) }
+ c.sequence(:name) { |n| "question_group-#{n}" }
c.description "Just another group"
end
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-03-19 15:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-19 15:44 [gentoo-commits] proj/recruiting-webapp:master commit in: spec/ Petteri Räty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox