Welcome to mirror list, hosted at ThFree Co, Russian Federation.

factories.rb « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7f7aac3146df8e6773b35f2002b64e20c1797f3 (plain)
1
2
3
4
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
106
107
108
109
110
111
112
113
114
115
#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

#For Guidance
#http://github.com/thoughtbot/factory_girl
# http://railscasts.com/episodes/158-factories-not-fixtures
#This inclsion, because gpg-agent(not needed) is never run and hence never sets any env. variables on a MAC

def r_str
  ActiveSupport::SecureRandom.hex(3)
end

Factory.define :profile do |p|
  p.sequence(:first_name) { |n| "Robert#{n}#{r_str}" }
  p.sequence(:last_name)  { |n| "Grimm#{n}#{r_str}" }
end


Factory.define :person do |p|
  p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" }
  p.sequence(:url)  { |n| "http://google-#{n}#{r_str}.com/" }
  p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export
  p.after_build do |person|
    person.profile ||= Factory.build(:profile, :person => person)
  end
  p.after_create do |person|
    person.profile.save
  end
end

Factory.define :searchable_person, :parent => :person do |p|
  p.after_build do |person|
    person.profile.searchable = true
  end
end

Factory.define :like do |x|
  x.association :author, :factory => :person
  x.association :post, :factory => :status_message
end

Factory.define :user do |u|
  u.sequence(:username) { |n| "bob#{n}#{r_str}" }
  u.sequence(:email) { |n| "bob#{n}#{r_str}@pivotallabs.com" }
  u.password "bluepin7"
  u.password_confirmation { |u| u.password }
  u.serialized_private_key  OpenSSL::PKey::RSA.generate(1024).export
  u.after_build do |user|
    user.person = Factory.build(:person, :profile => Factory.build(:profile),
                                :owner_id => user.id,
                                :serialized_public_key => user.encryption_key.public_key.export,
                                :diaspora_handle => "#{user.username}@#{AppConfig[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
  end
  u.after_create do |user|
    user.person.save
    user.person.profile.save
  end
end

Factory.define :user_with_aspect, :parent => :user do |u|
  u.after_create { |user| Factory(:aspect, :user => user) }
end

Factory.define :aspect do |aspect|
  aspect.name "generic"
  aspect.association :user
end

Factory.define(:status_message) do |m|
  m.sequence(:text) { |n| "jimmy's #{n} whales" }
  m.association :author, :factory => :person
  m.after_build do|m|
    m.diaspora_handle = m.author.diaspora_handle
  end
end

Factory.define :photo do |p|
  p.image File.open( File.dirname(__FILE__) + '/fixtures/button.png')
end

Factory.define :service do |service|
  service.nickname "sirrobertking"
  service.type "Services::Twitter"

  service.sequence(:uid)           { |token| "00000#{token}" }
  service.sequence(:access_token)  { |token| "12345#{token}" }
  service.sequence(:access_secret) { |token| "98765#{token}" }
end

Factory.define(:comment) do |comment|
  comment.sequence(:text) {|n| "#{n} cats"}
  comment.association(:author, :factory => :person)
  comment.association(:post, :factory => :status_message)
end

Factory.define(:notification) do |n|
  n.association :recipient, :factory => :user
  n.association :target, :factory => :comment
  n.type 'Notifications::AlsoCommented'

  n.after_build do |note|
    note.actors << Factory.build( :person )
  end
end

Factory.define(:activity_streams_photo, :class => ActivityStreams::Photo) do |p|
  p.association(:author, :factory => :person)
  p.image_url "http://example.com/awesome.png"
  p.image_height 9001
  p.image_width 4
  p.object_url "http://example.com/awesome_things.html"
  p.actor_url "http://notcubbi.es/cubber"
  p.provider_display_name "not cubbies"
end