Class: Voluntary::Test::RspecHelpers::Factories

Inherits:
Object
  • Object
show all
Defined in:
lib/voluntary/test/rspec_helpers/factories.rb

Class Method Summary collapse

Class Method Details

.codeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/voluntary/test/rspec_helpers/factories.rb', line 5

def self.code
  Proc.new do |factory_girl|
    factory_girl.factory :argument_topic do
      sequence(:name) { |n| "topic #{n}#{r_str}" } 
    end
    
    factory_girl.factory :user do
      sequence(:name) { |n| "user#{n}#{r_str}" }
      sequence(:email) { |n| "user#{n}#{r_str}@volontari.at" }
      first_name 'Mister'
      last_name { |u| u.name.humanize }
      country 'Germany'
      language 'en'
      interface_language 'en'
      password 'password'
      password_confirmation { |u| u.password }
    end
    
    factory_girl.factory :area do
      sequence(:name) { |n| "area #{n}" }
    end
    
    factory_girl.factory :product do
      name 'Product'
      user_id { FactoryGirl.create(:user, password: 'password', password_confirmation: 'password').id }
      area_ids { [Area.first.try(:id) || FactoryGirl.create(:area).id] }
      text Faker::Lorem.sentences(5).join(' ')
      
      after_build do |product|
        product.id = product.name.to_s.parameterize
      end
    end
    
    factory_girl.factory :organization do
      association :user
      sequence(:name) { |n| "area #{n}" }
    end
    
    factory_girl.factory :project do
      association :user
      sequence(:name) { |n| "project #{n}#{r_str}" }
      text Faker::Lorem.sentences(20).join(' ')
      
      after_build do |project|
        resource_has_many(project, :areas) 
      end
    end
    
    factory_girl.factory :comment do
      association :user
      association :commentable, factory: :project
      sequence(:name) { |n| "comment #{n}" }
      text Faker::Lorem.sentences(5).join(' ')
    end
    
    factory_girl.factory :story do
      association :project
      sequence(:name) { |n| "story#{n}#{r_str}" }
      text Faker::Lorem.sentences(10).join(' ')
      event 'setup_tasks'
      state_before 'initialized'
      state 'tasks_defined'
      
      ignore { task_factory :task }
      
      after_build do |story, evaluator|
        if evaluator.task_factory.blank?
          story.event = 'initialization'
          story.state_before = 'new'
          story.state = 'initialized'
        end
        
        story.tasks << Factory.build(evaluator.task_factory, offeror_id: story.project.user_id) if evaluator.task_factory
      end
    end
    
    factory_girl.factory :story_without_tasks do
      association :project
      sequence(:name) { |n| "story#{n}#{r_str}" }
      text Faker::Lorem.sentences(10).join(' ')
      language 'en'
      min_length 10
      max_length 50
      with_keywords true
      min_number_of_keywords 1
      max_number_of_keywords 3
      event 'initialization'
      state_before 'new'
      state 'initialized'
    end
    
    factory_girl.factory :task do
      sequence(:name) { |n| "task#{n}#{r_str}" }
      text Faker::Lorem.sentences(10).join(' ')
    end
    
    factory_girl.factory :thing do
      sequence(:name) { |n| "thing #{n} #{r_str}" }
    end
  end
end