I've used factory girl for creating single instances. It can do multiple
instances at once:

built_users   = build_list(:user, 25)created_users = create_list(:user, 25)

But for your use case, I would just create a normal Ruby method that does
the creation:

##
# This may not run, just pseudo-coded...
##
def build_calendar_dates(days)
  calendars = []
  days.times do |day|
    calendars << build(:calendar, :date => Date.today() - day)
  end
  calendars
end

Throw that in your test class, or create a separate help module to reuse
this elsewhere.

Regards,
Adam



On Mon, Aug 18, 2014 at 11:22 AM, Megan Byrne <[email protected]>
wrote:

> Hello all,
>
> I'm relatively new to testing and this has been tripping me up for a bit.
>
> I'm working in a code base that contains a Calendar Model (only contains a
> date field) which is used to help find other data from models with an SQL
> join for relevant date-ranges.
>
> I need to create a FactoryGirl factory which will be about 10 days worth
> of sequential dates (10 days back from whatever today's date is) so that I
> can use that to help test a method on another model which needs to join
> with the Calendar dates in order to find what it needs.
>
> So, the problem is that I cannot seem to figure out how to create a
> factory that loops through a set range of things.  Using sequence doesn't
> seem to work with a range and the blocks I've been using are just plain
> wrong.  Please help.
>
> I've been doing things like:
>
>
> FactoryGirl.define
>   factory :calander do
>     factory :dates do |d|
>       10.times do
>         d = 10
>         date {d.days.ago}
>         d -= 1
>       end
>     end
>   end
> end
>
> but this is clearly wrong...I guess I'm very confused about FactoryGirl in
> general
>
> Any help is greatly appreciated,
>
> Megan
>
> --
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
> ---
> You received this message because you are subscribed to the Google Groups
> "SD Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to