Replace factory_girl with fabrication

factory_girl has activesupport as dependency
This commit is contained in:
Benjamin Neff 2017-02-01 03:51:19 +01:00
parent b25e2293b0
commit 184954e09c
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
58 changed files with 396 additions and 395 deletions

View file

@ -15,8 +15,6 @@ Metrics/LineLength:
# the code easier to read (by naming things), but can also clutter the class # the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength: Metrics/MethodLength:
Max: 20 Max: 20
Exclude:
- "lib/diaspora_federation/test/factories.rb"
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength: Metrics/ClassLength:
@ -27,8 +25,6 @@ Metrics/ModuleLength:
# Raise AbcSize from 15 to 20 # Raise AbcSize from 15 to 20
Metrics/AbcSize: Metrics/AbcSize:
Max: 20 Max: 20
Exclude:
- "lib/diaspora_federation/test/factories.rb"
# No space makes the method definition shorter and differentiates # No space makes the method definition shorter and differentiates
# from a regular assignment. # from a regular assignment.
@ -165,7 +161,6 @@ Metrics/BlockLength:
- "**/*.rake" - "**/*.rake"
- "spec/**/*.rb" - "spec/**/*.rb"
- "test/dummy/config/**/*.rb" - "test/dummy/config/**/*.rb"
- "lib/diaspora_federation/test/factories.rb"
Rails/TimeZone: Rails/TimeZone:
Exclude: Exclude:

View file

@ -49,7 +49,6 @@ group :test do
gem "simplecov-rcov", "0.2.3", require: false gem "simplecov-rcov", "0.2.3", require: false
# test helpers # test helpers
gem "factory_girl_rails", "~> 4.7"
gem "fixture_builder", "0.5.0" gem "fixture_builder", "0.5.0"
gem "json-schema-rspec", "0.0.4" gem "json-schema-rspec", "0.0.4"
gem "rspec-collection_matchers", "~> 1.1.2" gem "rspec-collection_matchers", "~> 1.1.2"

View file

@ -13,7 +13,7 @@ PATH
rails (>= 4.2, < 6) rails (>= 4.2, < 6)
diaspora_federation-test (0.1.8) diaspora_federation-test (0.1.8)
diaspora_federation (= 0.1.8) diaspora_federation (= 0.1.8)
factory_girl (~> 4.7) fabrication (~> 2.16.0)
uuid (~> 2.3.8) uuid (~> 2.3.8)
GEM GEM
@ -73,11 +73,7 @@ GEM
erubis (2.7.0) erubis (2.7.0)
ethon (0.10.1) ethon (0.10.1)
ffi (>= 1.3.0) ffi (>= 1.3.0)
factory_girl (4.8.0) fabrication (2.16.1)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
faraday (0.12.0.1) faraday (0.12.0.1)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
faraday_middleware (0.11.0.1) faraday_middleware (0.11.0.1)
@ -304,7 +300,6 @@ DEPENDENCIES
diaspora_federation-json_schema! diaspora_federation-json_schema!
diaspora_federation-rails! diaspora_federation-rails!
diaspora_federation-test! diaspora_federation-test!
factory_girl_rails (~> 4.7)
fixture_builder (= 0.5.0) fixture_builder (= 0.5.0)
fuubar (= 2.2.0) fuubar (= 2.2.0)
guard-rspec guard-rspec

View file

@ -20,6 +20,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = "~> 2.1" s.required_ruby_version = "~> 2.1"
s.add_dependency "diaspora_federation", DiasporaFederation::VERSION s.add_dependency "diaspora_federation", DiasporaFederation::VERSION
s.add_dependency "factory_girl", "~> 4.7" s.add_dependency "fabrication", "~> 2.16.0"
s.add_dependency "uuid", "~> 2.3.8" s.add_dependency "uuid", "~> 2.3.8"
end end

View file

@ -1,4 +1,7 @@
require "diaspora_federation/test/factories" require "fabrication"
require "diaspora_federation"
require "diaspora_federation/test/entity_generator"
module DiasporaFederation module DiasporaFederation
# This module encapsulates helper functions maybe wanted by a testsuite of a diaspora_federation gem user application. # This module encapsulates helper functions maybe wanted by a testsuite of a diaspora_federation gem user application.

View file

@ -0,0 +1,25 @@
module DiasporaFederation
module Test
# Generator to instantiate entities
class EntityGenerator < Fabrication::Generator::Base
def self.supports?(klass)
klass.ancestors.include?(DiasporaFederation::Entity)
end
def build_instance
self._instance = _klass.new(_attributes)
end
def to_hash(attributes=[], _callbacks=[])
process_attributes(attributes)
_attributes.each_with_object({}) do |(name, value), hash|
hash[name.to_sym] = value
end
end
end
Fabrication.configure do |config|
config.generators << EntityGenerator
end
end
end

View file

@ -1,238 +1,228 @@
require "diaspora_federation"
require "factory_girl"
require "uuid" require "uuid"
require "securerandom"
require "diaspora_federation/test"
module DiasporaFederation module DiasporaFederation
module Test module Test
# Factories for federation entities # Factories for federation entities
module Factories module Factories
# Defines the federation entity factories Fabricate.sequence(:guid) { UUID.generate(:compact) }
def self.federation_factories Fabricate.sequence(:diaspora_id) {|n| "person-#{n}-#{SecureRandom.hex(3)}@localhost:3000" }
FactoryGirl.define do Fabricate.sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
initialize_with { new(attributes) }
sequence(:guid) { UUID.generate :compact }
sequence(:diaspora_id) {|n| "person-#{n}-#{SecureRandom.hex(3)}@localhost:3000" }
sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
factory :webfinger, class: DiasporaFederation::Discovery::WebFinger do Fabricator(:webfinger, class_name: DiasporaFederation::Discovery::WebFinger) do
guid guid { Fabricate.sequence(:guid) }
acct_uri { "acct:#{generate(:diaspora_id)}" } acct_uri { "acct:#{Fabricate.sequence(:diaspora_id)}" }
alias_url "http://localhost:3000/people/0123456789abcdef" alias_url "http://localhost:3000/people/0123456789abcdef"
hcard_url "http://localhost:3000/hcard/users/user" hcard_url "http://localhost:3000/hcard/users/user"
seed_url "http://localhost:3000/" seed_url "http://localhost:3000/"
profile_url "http://localhost:3000/u/user" profile_url "http://localhost:3000/u/user"
atom_url "http://localhost:3000/public/user.atom" atom_url "http://localhost:3000/public/user.atom"
salmon_url "http://localhost:3000/receive/users/0123456789abcdef" salmon_url "http://localhost:3000/receive/users/0123456789abcdef"
public_key public_key { Fabricate.sequence(:public_key) }
subscribe_url "http://localhost:3000/people?q={uri}" subscribe_url "http://localhost:3000/people?q={uri}"
end end
factory :h_card, class: DiasporaFederation::Discovery::HCard do Fabricator(:h_card, class_name: DiasporaFederation::Discovery::HCard) do
guid guid { Fabricate.sequence(:guid) }
nickname "some_name" nickname "some_name"
full_name "my name" full_name "my name"
first_name "my name" first_name "my name"
last_name "" last_name ""
url "http://localhost:3000/" url "http://localhost:3000/"
public_key public_key { Fabricate.sequence(:public_key) }
photo_large_url "/assets/user/default.png" photo_large_url "/assets/user/default.png"
photo_medium_url "/assets/user/default.png" photo_medium_url "/assets/user/default.png"
photo_small_url "/assets/user/default.png" photo_small_url "/assets/user/default.png"
searchable true searchable true
end end
factory :account_migration_entity, class: DiasporaFederation::Entities::AccountMigration do Fabricator(:account_deletion_entity, class_name: DiasporaFederation::Entities::AccountDeletion) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
profile { end
FactoryGirl.build(:profile_entity)
}
end
factory :person_entity, class: DiasporaFederation::Entities::Person do Fabricator(:account_migration_entity, class_name: DiasporaFederation::Entities::AccountMigration) do
guid author { Fabricate.sequence(:diaspora_id) }
author { generate(:diaspora_id) } profile { Fabricate(:profile_entity) }
url "http://localhost:3000/" end
exported_key { generate(:public_key) }
profile {
FactoryGirl.build(:profile_entity, author: author)
}
end
factory :profile_entity, class: DiasporaFederation::Entities::Profile do Fabricator(:person_entity, class_name: DiasporaFederation::Entities::Person) do
author { generate(:diaspora_id) } guid { Fabricate.sequence(:guid) }
first_name "my name" author { Fabricate.sequence(:diaspora_id) }
last_name "" url "http://localhost:3000/"
image_url "/assets/user/default.png" exported_key { Fabricate.sequence(:public_key) }
image_url_medium "/assets/user/default.png" profile {|attrs| Fabricate(:profile_entity, author: attrs[:author]) }
image_url_small "/assets/user/default.png" end
birthday "1988-07-15"
gender "Male"
bio "some text about me"
location "github"
searchable true
nsfw false
tag_string "#i #love #tags"
end
factory :location_entity, class: DiasporaFederation::Entities::Location do Fabricator(:profile_entity, class_name: DiasporaFederation::Entities::Profile) do
address "Vienna, Austria" author { Fabricate.sequence(:diaspora_id) }
lat 48.208174.to_s first_name "my name"
lng 16.373819.to_s last_name ""
end image_url "/assets/user/default.png"
image_url_medium "/assets/user/default.png"
image_url_small "/assets/user/default.png"
birthday "1988-07-15"
gender "Male"
bio "some text about me"
location "github"
searchable true
nsfw false
tag_string "#i #love #tags"
end
factory :photo_entity, class: DiasporaFederation::Entities::Photo do Fabricator(:location_entity, class_name: DiasporaFederation::Entities::Location) do
guid address "Vienna, Austria"
author { generate(:diaspora_id) } lat 48.208174.to_s
public(true) lng 16.373819.to_s
created_at { Time.now.utc } end
remote_photo_path "https://diaspora.example.tld/uploads/images/"
remote_photo_name "f2a41e9d2db4d9a199c8.jpg"
text "what you see here..."
status_message_guid { generate(:guid) }
height 480
width 800
end
factory :relayable_entity, class: DiasporaFederation::Entities::Relayable do Fabricator(:photo_entity, class_name: DiasporaFederation::Entities::Photo) do
parent_guid { generate(:guid) } guid { Fabricate.sequence(:guid) }
parent { FactoryGirl.build(:related_entity) } author { Fabricate.sequence(:diaspora_id) }
end public true
created_at { Time.now.utc }
remote_photo_path "https://diaspora.example.tld/uploads/images/"
remote_photo_name "f2a41e9d2db4d9a199c8.jpg"
text "what you see here..."
status_message_guid { Fabricate.sequence(:guid) }
height 480
width 800
end
factory :participation_entity, Fabricator(:relayable_entity, class_name: DiasporaFederation::Entities::Relayable) do
class: DiasporaFederation::Entities::Participation, parent: :relayable_entity do parent_guid { Fabricate.sequence(:guid) }
author { generate(:diaspora_id) } parent { Fabricate(:related_entity) }
guid end
parent_type "Post"
end
factory :status_message_entity, class: DiasporaFederation::Entities::StatusMessage do Fabricator(:participation_entity,
text "i am a very interesting status update" class_name: DiasporaFederation::Entities::Participation, from: :relayable_entity) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
guid guid { Fabricate.sequence(:guid) }
public(true) parent_type "Post"
created_at { Time.now.utc } end
end
factory :request_entity, class: DiasporaFederation::Entities::Request do Fabricator(:status_message_entity, class_name: DiasporaFederation::Entities::StatusMessage) do
author { generate(:diaspora_id) } text "i am a very interesting status update"
recipient { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
end guid { Fabricate.sequence(:guid) }
public true
created_at { Time.now.utc }
end
factory :contact_entity, class: DiasporaFederation::Entities::Contact do Fabricator(:request_entity, class_name: DiasporaFederation::Entities::Request) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
recipient { generate(:diaspora_id) } recipient { Fabricate.sequence(:diaspora_id) }
following true end
sharing true
end
factory :comment_entity, class: DiasporaFederation::Entities::Comment, parent: :relayable_entity do Fabricator(:contact_entity, class_name: DiasporaFederation::Entities::Contact) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
guid recipient { Fabricate.sequence(:diaspora_id) }
text "this is a very informative comment" following true
end sharing true
end
factory :like_entity, class: DiasporaFederation::Entities::Like, parent: :relayable_entity do Fabricator(:comment_entity, class_name: DiasporaFederation::Entities::Comment, from: :relayable_entity) do
positive true author { Fabricate.sequence(:diaspora_id) }
author { generate(:diaspora_id) } guid { Fabricate.sequence(:guid) }
guid text "this is a very informative comment"
parent_type "Post" end
end
factory :account_deletion_entity, class: DiasporaFederation::Entities::AccountDeletion do Fabricator(:like_entity, class_name: DiasporaFederation::Entities::Like, from: :relayable_entity) do
author { generate(:diaspora_id) } positive true
end author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
parent_type "Post"
end
factory :conversation_entity, class: DiasporaFederation::Entities::Conversation do Fabricator(:conversation_entity, class_name: DiasporaFederation::Entities::Conversation) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
guid guid { Fabricate.sequence(:guid) }
subject "this is a very informative subject" subject "this is a very informative subject"
created_at { Time.now.utc } created_at { Time.now.utc }
messages [] messages []
participants { Array.new(3) { generate(:diaspora_id) }.join(";") } participants { Array.new(3) { Fabricate.sequence(:diaspora_id) }.join(";") }
end end
factory :message_entity, class: DiasporaFederation::Entities::Message, parent: :relayable_entity do Fabricator(:message_entity, class_name: DiasporaFederation::Entities::Message, from: :relayable_entity) do
guid guid { Fabricate.sequence(:guid) }
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
text "this is a very informative text" text "this is a very informative text"
created_at { Time.now.utc } created_at { Time.now.utc }
conversation_guid { generate(:guid) } conversation_guid { Fabricate.sequence(:guid) }
end end
factory :relayable_retraction_entity, class: DiasporaFederation::Entities::RelayableRetraction do Fabricator(:relayable_retraction_entity, class_name: DiasporaFederation::Entities::RelayableRetraction) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
target_guid { generate(:guid) } target_guid { Fabricate.sequence(:guid) }
target_type "Comment" target_type "Comment"
target { FactoryGirl.build(:related_entity, author: author) } target {|attrs| Fabricate(:related_entity, author: attrs[:author]) }
end end
factory :reshare_entity, class: DiasporaFederation::Entities::Reshare do Fabricator(:reshare_entity, class_name: DiasporaFederation::Entities::Reshare) do
root_author { generate(:diaspora_id) } root_author { Fabricate.sequence(:diaspora_id) }
root_guid { generate(:guid) } root_guid { Fabricate.sequence(:guid) }
guid guid { Fabricate.sequence(:guid) }
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
public(true) public true
created_at { Time.now.utc } created_at { Time.now.utc }
provider_display_name { "the testsuite" } provider_display_name { "the testsuite" }
end end
factory :retraction_entity, class: DiasporaFederation::Entities::Retraction do Fabricator(:retraction_entity, class_name: DiasporaFederation::Entities::Retraction) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
target_guid { generate(:guid) } target_guid { Fabricate.sequence(:guid) }
target_type "Post" target_type "Post"
target { FactoryGirl.build(:related_entity, author: author) } target {|attrs| Fabricate(:related_entity, author: attrs[:author]) }
end end
factory :signed_retraction_entity, class: DiasporaFederation::Entities::SignedRetraction do Fabricator(:signed_retraction_entity, class_name: DiasporaFederation::Entities::SignedRetraction) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
target_guid { generate(:guid) } target_guid { Fabricate.sequence(:guid) }
target_type "Post" target_type "Post"
target { FactoryGirl.build(:related_entity, author: author) } target {|attrs| Fabricate(:related_entity, author: attrs[:author]) }
end end
factory :poll_answer_entity, class: DiasporaFederation::Entities::PollAnswer do Fabricator(:poll_answer_entity, class_name: DiasporaFederation::Entities::PollAnswer) do
guid guid { Fabricate.sequence(:guid) }
answer { "Obama is a bicycle" } answer { "Obama is a bicycle" }
end end
factory :poll_entity, class: DiasporaFederation::Entities::Poll do Fabricator(:poll_entity, class_name: DiasporaFederation::Entities::Poll) do
guid guid { Fabricate.sequence(:guid) }
question { "Select an answer" } question { "Select an answer" }
poll_answers { Array.new(3) { FactoryGirl.build(:poll_answer_entity) } } poll_answers { Array.new(3) { Fabricate(:poll_answer_entity) } }
end end
factory :poll_participation_entity, Fabricator(:poll_participation_entity,
class: DiasporaFederation::Entities::PollParticipation, parent: :relayable_entity do class_name: DiasporaFederation::Entities::PollParticipation, from: :relayable_entity) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
guid guid { Fabricate.sequence(:guid) }
poll_answer_guid { generate(:guid) } poll_answer_guid { Fabricate.sequence(:guid) }
end end
factory :event_entity, class: DiasporaFederation::Entities::Event do Fabricator(:event_entity, class_name: DiasporaFederation::Entities::Event) do |f|
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
guid guid { Fabricate.sequence(:guid) }
summary "Cool event" summary "Cool event"
description "You need to see this!" description "You need to see this!"
start { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) - 1.hour } start { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) - 1.hour }
add_attribute(:end) { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) + 1.hour } f.end { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) + 1.hour }
all_day false all_day false
timezone "Europe/Berlin" timezone "Europe/Berlin"
end end
factory :event_participation_entity, Fabricator(:event_participation_entity,
class: DiasporaFederation::Entities::EventParticipation, parent: :relayable_entity do class_name: DiasporaFederation::Entities::EventParticipation, from: :relayable_entity) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
guid guid { Fabricate.sequence(:guid) }
status "accepted" status "accepted"
end end
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do Fabricator(:related_entity, class_name: DiasporaFederation::Entities::RelatedEntity) do
author { generate(:diaspora_id) } author { Fabricate.sequence(:diaspora_id) }
local true local true
public false public false
parent nil parent nil
end
end
end end
end end
end end

View file

@ -3,7 +3,7 @@ module DiasporaFederation
routes { DiasporaFederation::Engine.routes } routes { DiasporaFederation::Engine.routes }
let(:guid) { "12345678901234567890" } let(:guid) { "12345678901234567890" }
let(:post) { FactoryGirl.build(:status_message_entity, guid: guid, author: alice.diaspora_id) } let(:post) { Fabricate(:status_message_entity, guid: guid, author: alice.diaspora_id) }
describe "GET #fetch" do describe "GET #fetch" do
it "returns the magic-envelope with the status message" do it "returns the magic-envelope with the status message" do

View file

@ -1,46 +1,42 @@
require "diaspora_federation/test" require "diaspora_federation/test/factories"
DiasporaFederation::Test::Factories.federation_factories Fabricator(:person) do
diaspora_id { Fabricate.sequence(:diaspora_id) }
url "http://somehost:3000/"
serialized_public_key { Fabricate.sequence(:public_key) }
end
FactoryGirl.define do Fabricator(:user, class_name: Person) do
factory :person do diaspora_id { Fabricate.sequence(:diaspora_id) }
diaspora_id url "http://localhost:3000/"
url "http://somehost:3000/" after_build do |user|
serialized_public_key { generate(:public_key) } private_key = OpenSSL::PKey::RSA.generate(1024)
end user.serialized_private_key = private_key.export
user.serialized_public_key = private_key.public_key.export
factory :user, class: Person do
diaspora_id
url "http://localhost:3000/"
after(:build) do |user|
private_key = OpenSSL::PKey::RSA.generate(1024)
user.serialized_private_key = private_key.export
user.serialized_public_key = private_key.public_key.export
end
end
factory :post, class: Entity do
entity_type "Post"
author { FactoryGirl.build(:person) }
end
factory :comment, class: Entity do
entity_type "Comment"
author { FactoryGirl.build(:person) }
end
factory :poll, class: Entity do
entity_type "Poll"
author { FactoryGirl.build(:person) }
end
factory :event, class: Entity do
entity_type "Event"
author { FactoryGirl.build(:person) }
end
factory :conversation, class: Entity do
entity_type "Conversation"
author { FactoryGirl.build(:person) }
end end
end end
Fabricator(:post, class_name: Entity) do
on_init { init_with(entity_type: "Post") }
author { Fabricate(:person) }
end
Fabricator(:comment, class_name: Entity) do
on_init { init_with(entity_type: "Comment") }
author { Fabricate(:person) }
end
Fabricator(:poll, class_name: Entity) do
on_init { init_with(entity_type: "Poll") }
author { Fabricate(:person) }
end
Fabricator(:event, class_name: Entity) do
on_init { init_with(entity_type: "Event") }
author { Fabricate(:person) }
end
Fabricator(:conversation, class_name: Entity) do
on_init { init_with(entity_type: "Conversation") }
author { Fabricate(:person) }
end

View file

@ -56,7 +56,7 @@ KEY
let(:new_data) { "foobar" } let(:new_data) { "foobar" }
let(:text) { "this is a very informative comment" } let(:text) { "this is a very informative comment" }
let(:parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:comment) { let(:comment) {
Entities::Comment.new( Entities::Comment.new(
author: author, guid: guid, parent_guid: parent_guid, text: text, parent: parent, new_data: new_data author: author, guid: guid, parent_guid: parent_guid, text: text, parent: parent, new_data: new_data
@ -210,7 +210,7 @@ XML
end end
context "parsing on every other pod" do context "parsing on every other pod" do
let(:parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id, local: false) } let(:parent) { Fabricate(:related_entity, author: bob.diaspora_id, local: false) }
before do before do
expect_callback(:fetch_public_key, author).and_return(author_key.public_key) expect_callback(:fetch_public_key, author).and_return(author_key.public_key)

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Discovery::HCard do describe Discovery::HCard do
let(:person) { FactoryGirl.create(:person) } let(:person) { Fabricate(:person) }
let(:photo_large_url) { "#{person.url}/upload/large.png" } let(:photo_large_url) { "#{person.url}/upload/large.png" }
let(:photo_medium_url) { "#{person.url}/upload/medium.png" } let(:photo_medium_url) { "#{person.url}/upload/medium.png" }
let(:photo_small_url) { "#{person.url}/upload/small.png" } let(:photo_small_url) { "#{person.url}/upload/small.png" }

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Discovery::WebFinger do describe Discovery::WebFinger do
let(:person) { FactoryGirl.create(:person) } let(:person) { Fabricate(:person) }
let(:acct) { "acct:#{person.diaspora_id}" } let(:acct) { "acct:#{person.diaspora_id}" }
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) } let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::AccountDeletion do describe Entities::AccountDeletion do
let(:data) { FactoryGirl.attributes_for(:account_deletion_entity) } let(:data) { Fabricate.attributes_for(:account_deletion_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<account_deletion> <account_deletion>

View file

@ -3,9 +3,8 @@ module DiasporaFederation
let(:new_diaspora_id) { alice.diaspora_id } let(:new_diaspora_id) { alice.diaspora_id }
let(:new_author_pkey) { alice.private_key } let(:new_author_pkey) { alice.private_key }
let(:hash) { let(:hash) {
FactoryGirl.attributes_for( Fabricate.attributes_for(:account_deletion_entity).merge(
:account_migration_entity, profile: Fabricate(:profile_entity, author: new_diaspora_id)
profile: FactoryGirl.build(:profile_entity, author: new_diaspora_id)
) )
} }
let(:data) { let(:data) {

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Comment do describe Entities::Comment do
let(:parent) { FactoryGirl.create(:post, author: bob) } let(:parent) { Fabricate(:post, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl Fabricate
.attributes_for( .attributes_for(
:comment_entity, :comment_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
@ -65,7 +65,7 @@ JSON
it "parses the created_at from the xml if it is included and correctly signed" do it "parses the created_at from the xml if it is included and correctly signed" do
created_at = Time.now.utc.change(usec: 0) - 1.minute created_at = Time.now.utc.change(usec: 0) - 1.minute
comment_data = FactoryGirl.attributes_for(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid) comment_data = Fabricate.attributes_for(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid)
comment_data[:created_at] = created_at comment_data[:created_at] = created_at
comment_data[:parent] = parent_entity comment_data[:parent] = parent_entity
comment = described_class.new(comment_data, %i(author guid parent_guid text created_at)) comment = described_class.new(comment_data, %i(author guid parent_guid text created_at))

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Contact do describe Entities::Contact do
let(:data) { FactoryGirl.attributes_for(:contact_entity) } let(:data) { Fabricate.attributes_for(:contact_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<contact> <contact>

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Conversation do describe Entities::Conversation do
let(:parent) { FactoryGirl.create(:conversation, author: bob) } let(:parent) { Fabricate(:conversation, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:signed_msg1) { let(:signed_msg1) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:message_entity, :message_entity,
author: bob.diaspora_id, author: bob.diaspora_id,
parent_guid: parent.guid, parent_guid: parent.guid,
@ -11,7 +11,7 @@ module DiasporaFederation
).tap {|hash| add_signatures(hash, Entities::Message) } ).tap {|hash| add_signatures(hash, Entities::Message) }
} }
let(:signed_msg2) { let(:signed_msg2) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:message_entity, :message_entity,
author: bob.diaspora_id, author: bob.diaspora_id,
parent_guid: parent.guid, parent_guid: parent.guid,
@ -19,11 +19,11 @@ module DiasporaFederation
).tap {|hash| add_signatures(hash, Entities::Message) } ).tap {|hash| add_signatures(hash, Entities::Message) }
} }
let(:data) { let(:data) {
FactoryGirl.attributes_for(:conversation_entity).merge!( Fabricate.attributes_for(:conversation_entity).merge!(
messages: [Entities::Message.new(signed_msg1), Entities::Message.new(signed_msg2)], messages: [Entities::Message.new(signed_msg1), Entities::Message.new(signed_msg2)],
author: bob.diaspora_id, author: bob.diaspora_id,
guid: parent.guid, guid: parent.guid,
participants: "#{bob.diaspora_id};#{FactoryGirl.generate(:diaspora_id)}" participants: "#{bob.diaspora_id};#{Fabricate.sequence(:diaspora_id)}"
) )
} }

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::EventParticipation do describe Entities::EventParticipation do
let(:parent) { FactoryGirl.create(:event, author: bob) } let(:parent) { Fabricate(:event, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:event_participation_entity, :event_participation_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
parent_guid: parent.guid, parent_guid: parent.guid,

View file

@ -1,8 +1,8 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Event do describe Entities::Event do
let(:location) { FactoryGirl.build(:location_entity) } let(:location) { Fabricate(:location_entity) }
let(:data) { let(:data) {
FactoryGirl.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location) Fabricate.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location)
} }
let(:xml) { <<-XML } let(:xml) { <<-XML }

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Like do describe Entities::Like do
let(:parent) { FactoryGirl.create(:post, author: bob) } let(:parent) { Fabricate(:post, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:like_entity, :like_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
parent_guid: parent.guid, parent_guid: parent.guid,

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Location do describe Entities::Location do
let(:data) { FactoryGirl.attributes_for(:location_entity) } let(:data) { Fabricate.attributes_for(:location_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<location> <location>

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Message do describe Entities::Message do
let(:parent) { FactoryGirl.create(:conversation, author: bob) } let(:parent) { Fabricate(:conversation, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl Fabricate
.attributes_for(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity) .attributes_for(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
.tap {|hash| add_signatures(hash) } .tap {|hash| add_signatures(hash) }
} }
@ -44,7 +44,7 @@ XML
it "does not allow any other person" do it "does not allow any other person" do
expect_callback(:fetch_related_entity, "Conversation", entity.conversation_guid).and_return(parent_entity) expect_callback(:fetch_related_entity, "Conversation", entity.conversation_guid).and_return(parent_entity)
invalid_sender = FactoryGirl.generate(:diaspora_id) invalid_sender = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_sender)).to be_falsey expect(entity.sender_valid?(invalid_sender)).to be_falsey
end end

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Participation do describe Entities::Participation do
let(:parent) { FactoryGirl.create(:post, author: bob) } let(:parent) { Fabricate(:post, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:participation_entity, :participation_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
parent_guid: parent.guid, parent_guid: parent.guid,
@ -84,7 +84,7 @@ JSON
} }
it "succeeds when the parent is local" do it "succeeds when the parent is local" do
local_parent = FactoryGirl.build(:related_entity, local: true) local_parent = Fabricate(:related_entity, local: true)
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(local_parent) expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(local_parent)
expect { expect {
@ -101,7 +101,7 @@ JSON
end end
it "raises ParentNotLocal when the parent is not local" do it "raises ParentNotLocal when the parent is not local" do
remote_parent = FactoryGirl.build(:related_entity, local: false) remote_parent = Fabricate(:related_entity, local: false)
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(remote_parent) expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(remote_parent)
expect { expect {

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Person do describe Entities::Person do
let(:data) { FactoryGirl.attributes_for(:person_entity) } let(:data) { Fabricate.attributes_for(:person_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<person> <person>

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Photo do describe Entities::Photo do
let(:data) { FactoryGirl.attributes_for(:photo_entity) } let(:data) { Fabricate.attributes_for(:photo_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<photo> <photo>

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::PollAnswer do describe Entities::PollAnswer do
let(:data) { FactoryGirl.attributes_for(:poll_answer_entity) } let(:data) { Fabricate.attributes_for(:poll_answer_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<poll_answer> <poll_answer>

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::PollParticipation do describe Entities::PollParticipation do
let(:parent) { FactoryGirl.create(:poll, author: bob) } let(:parent) { Fabricate(:poll, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:poll_participation_entity, :poll_participation_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
parent_guid: parent.guid, parent_guid: parent.guid,

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Poll do describe Entities::Poll do
let(:data) { FactoryGirl.attributes_for(:poll_entity) } let(:data) { Fabricate.attributes_for(:poll_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<poll> <poll>

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Profile do describe Entities::Profile do
let(:data) { FactoryGirl.attributes_for(:profile_entity) } let(:data) { Fabricate.attributes_for(:profile_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<profile> <profile>

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::RelatedEntity do describe Entities::RelatedEntity do
let(:data) { FactoryGirl.attributes_for(:related_entity) } let(:data) { Fabricate.attributes_for(:related_entity) }
let(:string) { "RelatedEntity" } let(:string) { "RelatedEntity" }
it_behaves_like "an Entity subclass" it_behaves_like "an Entity subclass"

View file

@ -1,15 +1,15 @@
module DiasporaFederation module DiasporaFederation
describe Entities::RelayableRetraction do describe Entities::RelayableRetraction do
let(:target) { FactoryGirl.create(:comment, author: bob) } let(:target) { Fabricate(:comment, author: bob) }
let(:target_entity) { let(:target_entity) {
FactoryGirl.build( Fabricate(
:related_entity, :related_entity,
author: bob.diaspora_id, author: bob.diaspora_id,
parent: FactoryGirl.build(:related_entity, author: alice.diaspora_id) parent: Fabricate(:related_entity, author: alice.diaspora_id)
) )
} }
let(:data) { let(:data) {
FactoryGirl.build( Fabricate(
:relayable_retraction_entity, :relayable_retraction_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
target_guid: target.guid, target_guid: target.guid,
@ -41,11 +41,11 @@ XML
describe "#to_xml" do describe "#to_xml" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) } let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) } let(:hash) { Fabricate.attributes_for(:relayable_retraction_entity) }
it "updates author signature when it was nil and key was supplied and author is not parent author" do it "updates author signature when it was nil and key was supplied and author is not parent author" do
parent = FactoryGirl.build(:related_entity, author: bob.diaspora_id) parent = Fabricate(:related_entity, author: bob.diaspora_id)
hash[:target] = FactoryGirl.build(:related_entity, author: hash[:author], parent: parent) hash[:target] = Fabricate(:related_entity, author: hash[:author], parent: parent)
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey) expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -58,8 +58,8 @@ XML
end end
it "sets parent author signature when author is parent author" do it "sets parent author signature when author is parent author" do
parent = FactoryGirl.build(:related_entity, author: hash[:author]) parent = Fabricate(:related_entity, author: hash[:author])
hash[:target] = FactoryGirl.build(:related_entity, author: hash[:author], parent: parent) hash[:target] = Fabricate(:related_entity, author: hash[:author], parent: parent)
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey) expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -72,8 +72,8 @@ XML
end end
it "updates parent author signature when it was nil, key was supplied and sender is author of the parent" do it "updates parent author signature when it was nil, key was supplied and sender is author of the parent" do
parent = FactoryGirl.build(:related_entity, author: hash[:author]) parent = Fabricate(:related_entity, author: hash[:author])
hash[:target] = FactoryGirl.build(:related_entity, author: bob.diaspora_id, parent: parent) hash[:target] = Fabricate(:related_entity, author: bob.diaspora_id, parent: parent)
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey) expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -105,7 +105,7 @@ XML
describe "#to_retraction" do describe "#to_retraction" do
it "copies the attributes to a Retraction" do it "copies the attributes to a Retraction" do
relayable_retraction = FactoryGirl.build(:relayable_retraction_entity) relayable_retraction = Fabricate(:relayable_retraction_entity)
retraction = relayable_retraction.to_retraction retraction = relayable_retraction.to_retraction
expect(retraction).to be_a(Entities::Retraction) expect(retraction).to be_a(Entities::Retraction)

View file

@ -3,13 +3,13 @@ module DiasporaFederation
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) } let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:parent_pkey) { OpenSSL::PKey::RSA.generate(1024) } let(:parent_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:guid) { FactoryGirl.generate(:guid) } let(:guid) { Fabricate.sequence(:guid) }
let(:parent_guid) { FactoryGirl.generate(:guid) } let(:parent_guid) { Fabricate.sequence(:guid) }
let(:author) { FactoryGirl.generate(:diaspora_id) } let(:author) { Fabricate.sequence(:diaspora_id) }
let(:property) { "hello" } let(:property) { "hello" }
let(:new_property) { "some text" } let(:new_property) { "some text" }
let(:local_parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:local_parent) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:remote_parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id, local: false) } let(:remote_parent) { Fabricate(:related_entity, author: bob.diaspora_id, local: false) }
let(:hash) { {guid: guid, author: author, parent_guid: parent_guid, parent: local_parent, property: property} } let(:hash) { {guid: guid, author: author, parent_guid: parent_guid, parent: local_parent, property: property} }
let(:hash_with_fake_signatures) { hash.merge!(author_signature: "aa", parent_author_signature: "bb") } let(:hash_with_fake_signatures) { hash.merge!(author_signature: "aa", parent_author_signature: "bb") }
@ -521,7 +521,7 @@ XML
it "does not allow any random author" do it "does not allow any random author" do
entity = Entities::SomeRelayable.new(hash) entity = Entities::SomeRelayable.new(hash)
invalid_author = FactoryGirl.generate(:diaspora_id) invalid_author = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_author)).to be_falsey expect(entity.sender_valid?(invalid_author)).to be_falsey
end end

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Request do describe Entities::Request do
let(:data) { FactoryGirl.attributes_for(:request_entity) } let(:data) { Fabricate.attributes_for(:request_entity) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<request> <request>
@ -17,7 +17,7 @@ XML
describe "#to_contact" do describe "#to_contact" do
it "copies the attributes to a Contact" do it "copies the attributes to a Contact" do
request = FactoryGirl.build(:request_entity) request = Fabricate(:request_entity)
contact = request.to_contact contact = request.to_contact
expect(contact).to be_a(Entities::Contact) expect(contact).to be_a(Entities::Contact)

View file

@ -1,7 +1,7 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Reshare do describe Entities::Reshare do
let(:root) { FactoryGirl.create(:post, author: bob) } let(:root) { Fabricate(:post, author: bob) }
let(:data) { FactoryGirl.attributes_for(:reshare_entity, root_guid: root.guid, root_author: bob.diaspora_id) } let(:data) { Fabricate.attributes_for(:reshare_entity, root_guid: root.guid, root_author: bob.diaspora_id) }
let(:xml) { <<-XML } let(:xml) { <<-XML }
<reshare> <reshare>

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::Retraction do describe Entities::Retraction do
let(:target) { FactoryGirl.create(:post, author: bob) } let(:target) { Fabricate(:post, author: bob) }
let(:target_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) } let(:target_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl.attributes_for( Fabricate.attributes_for(
:retraction_entity, :retraction_entity,
target_guid: target.guid, target_guid: target.guid,
target_type: target.entity_type, target_type: target.entity_type,
@ -37,7 +37,7 @@ XML
it "does not allow any random author" do it "does not allow any random author" do
entity = Entities::Retraction.new(data) entity = Entities::Retraction.new(data)
invalid_author = FactoryGirl.generate(:diaspora_id) invalid_author = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_author)).to be_falsey expect(entity.sender_valid?(invalid_author)).to be_falsey
end end
@ -46,10 +46,10 @@ XML
%w(Comment Like PollParticipation).each do |target_type| %w(Comment Like PollParticipation).each do |target_type|
context "#{target_type} target" do context "#{target_type} target" do
let(:relayable_target) { let(:relayable_target) {
FactoryGirl.build( Fabricate(
:related_entity, :related_entity,
author: bob.diaspora_id, author: bob.diaspora_id,
parent: FactoryGirl.build(:related_entity, author: alice.diaspora_id) parent: Fabricate(:related_entity, author: alice.diaspora_id)
) )
} }
let(:relayable_data) { data.merge(target_type: target_type, target: relayable_target) } let(:relayable_data) { data.merge(target_type: target_type, target: relayable_target) }
@ -68,7 +68,7 @@ XML
it "does not allow any random author" do it "does not allow any random author" do
entity = Entities::Retraction.new(relayable_data) entity = Entities::Retraction.new(relayable_data)
invalid_author = FactoryGirl.generate(:diaspora_id) invalid_author = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_author)).to be_falsey expect(entity.sender_valid?(invalid_author)).to be_falsey
end end

View file

@ -1,9 +1,9 @@
module DiasporaFederation module DiasporaFederation
describe Entities::SignedRetraction do describe Entities::SignedRetraction do
let(:target) { FactoryGirl.create(:post, author: alice) } let(:target) { Fabricate(:post, author: alice) }
let(:target_entity) { FactoryGirl.build(:related_entity, author: alice.diaspora_id) } let(:target_entity) { Fabricate(:related_entity, author: alice.diaspora_id) }
let(:data) { let(:data) {
FactoryGirl.build( Fabricate(
:signed_retraction_entity, :signed_retraction_entity,
author: alice.diaspora_id, author: alice.diaspora_id,
target_guid: target.guid, target_guid: target.guid,
@ -31,7 +31,7 @@ XML
describe "#to_xml" do describe "#to_xml" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) } let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) } let(:hash) { Fabricate.attributes_for(:signed_retraction_entity) }
it "updates author signature when it was nil and key was supplied" do it "updates author signature when it was nil and key was supplied" do
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey) expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -62,7 +62,7 @@ XML
describe "#to_retraction" do describe "#to_retraction" do
it "copies the attributes to a Retraction" do it "copies the attributes to a Retraction" do
signed_retraction = FactoryGirl.build(:signed_retraction_entity) signed_retraction = Fabricate(:signed_retraction_entity)
retraction = signed_retraction.to_retraction retraction = signed_retraction.to_retraction
expect(retraction).to be_a(Entities::Retraction) expect(retraction).to be_a(Entities::Retraction)

View file

@ -1,10 +1,10 @@
module DiasporaFederation module DiasporaFederation
describe Entities::StatusMessage do describe Entities::StatusMessage do
let(:photo1) { FactoryGirl.build(:photo_entity, author: alice.diaspora_id) } let(:photo1) { Fabricate(:photo_entity, author: alice.diaspora_id) }
let(:photo2) { FactoryGirl.build(:photo_entity, author: alice.diaspora_id) } let(:photo2) { Fabricate(:photo_entity, author: alice.diaspora_id) }
let(:location) { FactoryGirl.build(:location_entity) } let(:location) { Fabricate(:location_entity) }
let(:data) { let(:data) {
FactoryGirl.attributes_for(:status_message_entity).merge( Fabricate.attributes_for(:status_message_entity).merge(
author: alice.diaspora_id, author: alice.diaspora_id,
photos: [photo1, photo2], photos: [photo1, photo2],
location: location, location: location,
@ -140,7 +140,7 @@ XML
context "nested entities" do context "nested entities" do
it "validates that nested photos have the same author" do it "validates that nested photos have the same author" do
invalid_data = data.merge(author: FactoryGirl.generate(:diaspora_id)) invalid_data = data.merge(author: Fabricate.sequence(:diaspora_id))
expect { expect {
Entities::StatusMessage.new(invalid_data) Entities::StatusMessage.new(invalid_data)
}.to raise_error Entity::ValidationError }.to raise_error Entity::ValidationError

View file

@ -417,7 +417,7 @@ JSON
end end
it "is not added to xml if #to_xml returns nil" do it "is not added to xml if #to_xml returns nil" do
entity = Entities::TestEntityWithRelatedEntity.new(test: "test", parent: FactoryGirl.build(:related_entity)) entity = Entities::TestEntityWithRelatedEntity.new(test: "test", parent: Fabricate(:related_entity))
xml = entity.to_xml xml = entity.to_xml
expect(xml.children).to have_exactly(1).items expect(xml.children).to have_exactly(1).items
xml.children.first.name = "test" xml.children.first.name = "test"

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Federation::Fetcher do describe Federation::Fetcher do
let(:post) { FactoryGirl.build(:status_message_entity, public: true) } let(:post) { Fabricate(:status_message_entity, public: true) }
let(:post_magic_env) { Salmon::MagicEnvelope.new(post, post.author).envelop(alice.private_key).to_xml } let(:post_magic_env) { Salmon::MagicEnvelope.new(post, post.author).envelop(alice.private_key).to_xml }
describe ".fetch_public" do describe ".fetch_public" do

View file

@ -1,7 +1,7 @@
module DiasporaFederation module DiasporaFederation
describe Federation::Receiver::Private do describe Federation::Receiver::Private do
let(:recipient) { 42 } let(:recipient) { 42 }
let(:post) { FactoryGirl.build(:status_message_entity, public: false) } let(:post) { Fabricate(:status_message_entity, public: false) }
let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) } let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) }
describe "#receive" do describe "#receive" do
@ -12,7 +12,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(post, sender) bad_env = Salmon::MagicEnvelope.new(post, sender)
expect { expect {
@ -27,7 +27,7 @@ module DiasporaFederation
end end
context "with relayable" do context "with relayable" do
let(:comment) { FactoryGirl.build(:comment_entity, parent: FactoryGirl.build(:related_entity, public: false)) } let(:comment) { Fabricate(:comment_entity, parent: Fabricate(:related_entity, public: false)) }
it "receives a comment from the author" do it "receives a comment from the author" do
magic_env = Salmon::MagicEnvelope.new(comment, comment.author) magic_env = Salmon::MagicEnvelope.new(comment, comment.author)
@ -46,7 +46,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(comment, sender) bad_env = Salmon::MagicEnvelope.new(comment, sender)
expect { expect {
@ -57,7 +57,7 @@ module DiasporaFederation
context "with retraction" do context "with retraction" do
context "for a post" do context "for a post" do
let(:retraction) { FactoryGirl.build(:retraction_entity, target_type: "Post") } let(:retraction) { Fabricate(:retraction_entity, target_type: "Post") }
it "retracts a post from the author" do it "retracts a post from the author" do
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author) magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author)
@ -68,7 +68,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender) bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect { expect {
@ -79,10 +79,10 @@ module DiasporaFederation
context "for a comment" do context "for a comment" do
let(:retraction) { let(:retraction) {
FactoryGirl.build( Fabricate(
:retraction_entity, :retraction_entity,
target_type: "Comment", target_type: "Comment",
target: FactoryGirl.build(:related_entity, parent: FactoryGirl.build(:related_entity)) target: Fabricate(:related_entity, parent: Fabricate(:related_entity))
) )
} }
@ -103,7 +103,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender) bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect { expect {

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Federation::Receiver::Public do describe Federation::Receiver::Public do
let(:post) { FactoryGirl.build(:status_message_entity) } let(:post) { Fabricate(:status_message_entity) }
let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) } let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) }
describe "#receive" do describe "#receive" do
@ -11,7 +11,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(post, sender) bad_env = Salmon::MagicEnvelope.new(post, sender)
expect { expect {
@ -20,7 +20,7 @@ module DiasporaFederation
end end
context "with relayable" do context "with relayable" do
let(:comment) { FactoryGirl.build(:comment_entity) } let(:comment) { Fabricate(:comment_entity) }
it "receives a comment from the author" do it "receives a comment from the author" do
magic_env = Salmon::MagicEnvelope.new(comment, comment.author) magic_env = Salmon::MagicEnvelope.new(comment, comment.author)
@ -39,7 +39,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(comment, sender) bad_env = Salmon::MagicEnvelope.new(comment, sender)
expect { expect {
@ -50,7 +50,7 @@ module DiasporaFederation
context "with retraction" do context "with retraction" do
context "for a post" do context "for a post" do
let(:retraction) { FactoryGirl.build(:retraction_entity, target_type: "Post") } let(:retraction) { Fabricate(:retraction_entity, target_type: "Post") }
it "retracts a post from the author" do it "retracts a post from the author" do
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.author) magic_env = Salmon::MagicEnvelope.new(retraction, retraction.author)
@ -61,7 +61,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender) bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect { expect {
@ -72,10 +72,10 @@ module DiasporaFederation
context "for a comment" do context "for a comment" do
let(:retraction) { let(:retraction) {
FactoryGirl.build( Fabricate(
:retraction_entity, :retraction_entity,
target_type: "Comment", target_type: "Comment",
target: FactoryGirl.build(:related_entity, parent: FactoryGirl.build(:related_entity)) target: Fabricate(:related_entity, parent: Fabricate(:related_entity))
) )
} }
@ -96,7 +96,7 @@ module DiasporaFederation
end end
it "validates the sender" do it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id) sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender) bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect { expect {
@ -108,7 +108,7 @@ module DiasporaFederation
context "validates if it is public" do context "validates if it is public" do
it "allows public entities" do it "allows public entities" do
public_post = FactoryGirl.build(:status_message_entity, public: true) public_post = Fabricate(:status_message_entity, public: true)
magic_env = Salmon::MagicEnvelope.new(public_post, public_post.author) magic_env = Salmon::MagicEnvelope.new(public_post, public_post.author)
expect_callback(:receive_entity, public_post, public_post.author, nil) expect_callback(:receive_entity, public_post, public_post.author, nil)
@ -117,7 +117,7 @@ module DiasporaFederation
end end
it "does not allow non-public entities" do it "does not allow non-public entities" do
private_post = FactoryGirl.build(:status_message_entity, public: false) private_post = Fabricate(:status_message_entity, public: false)
magic_env = Salmon::MagicEnvelope.new(private_post, private_post.author) magic_env = Salmon::MagicEnvelope.new(private_post, private_post.author)
expect { expect {
@ -126,7 +126,7 @@ module DiasporaFederation
end end
it "allows entities without public flag" do it "allows entities without public flag" do
profile = FactoryGirl.build(:profile_entity) profile = Fabricate(:profile_entity)
magic_env = Salmon::MagicEnvelope.new(profile, profile.author) magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
expect_callback(:receive_entity, profile, profile.author, nil) expect_callback(:receive_entity, profile, profile.author, nil)

View file

@ -4,7 +4,7 @@ module DiasporaFederation
let(:recipient_key) { OpenSSL::PKey::RSA.generate(1024) } let(:recipient_key) { OpenSSL::PKey::RSA.generate(1024) }
describe ".receive_public" do describe ".receive_public" do
let(:post) { FactoryGirl.build(:status_message_entity) } let(:post) { Fabricate(:status_message_entity) }
it "parses the entity with magic envelope receiver" do it "parses the entity with magic envelope receiver" do
expect_callback(:fetch_public_key, post.author).and_return(sender_key) expect_callback(:fetch_public_key, post.author).and_return(sender_key)
@ -44,7 +44,7 @@ module DiasporaFederation
end end
describe ".receive_private" do describe ".receive_private" do
let(:post) { FactoryGirl.build(:status_message_entity, public: false) } let(:post) { Fabricate(:status_message_entity, public: false) }
it "parses the entity with magic envelope receiver" do it "parses the entity with magic envelope receiver" do
expect_callback(:fetch_public_key, post.author).and_return(sender_key) expect_callback(:fetch_public_key, post.author).and_return(sender_key)

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Federation::Sender::HydraWrapper do describe Federation::Sender::HydraWrapper do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) } let(:sender_id) { Fabricate.sequence(:diaspora_id) }
let(:obj_str) { "status_message@guid" } let(:obj_str) { "status_message@guid" }
let(:xml) { "<xml>post</xml>" } let(:xml) { "<xml>post</xml>" }
let(:url) { "http://example.org/receive/public" } let(:url) { "http://example.org/receive/public" }

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Federation::Sender do describe Federation::Sender do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) } let(:sender_id) { Fabricate.sequence(:diaspora_id) }
let(:obj_str) { "status_message@guid" } let(:obj_str) { "status_message@guid" }
let(:hydra_wrapper) { double } let(:hydra_wrapper) { double }

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Salmon::EncryptedMagicEnvelope do describe Salmon::EncryptedMagicEnvelope do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) } let(:sender_id) { Fabricate.sequence(:diaspora_id) }
let(:sender_key) { OpenSSL::PKey::RSA.generate(512) } # use small key for speedy specs let(:sender_key) { OpenSSL::PKey::RSA.generate(512) } # use small key for speedy specs
let(:entity) { Entities::TestEntity.new(test: "abcd") } let(:entity) { Entities::TestEntity.new(test: "abcd") }
let(:magic_env) { Salmon::MagicEnvelope.new(entity, sender_id).envelop(sender_key) } let(:magic_env) { Salmon::MagicEnvelope.new(entity, sender_id).envelop(sender_key) }

View file

@ -1,6 +1,6 @@
module DiasporaFederation module DiasporaFederation
describe Salmon::MagicEnvelope do describe Salmon::MagicEnvelope do
let(:sender) { FactoryGirl.generate(:diaspora_id) } let(:sender) { Fabricate.sequence(:diaspora_id) }
let(:privkey) { OpenSSL::PKey::RSA.generate(512) } # use small key for speedy specs let(:privkey) { OpenSSL::PKey::RSA.generate(512) } # use small key for speedy specs
let(:payload) { Entities::TestEntity.new(test: "asdf") } let(:payload) { Entities::TestEntity.new(test: "asdf") }
let(:envelope) { Salmon::MagicEnvelope.new(payload, sender) } let(:envelope) { Salmon::MagicEnvelope.new(payload, sender) }
@ -139,7 +139,7 @@ module DiasporaFederation
end end
it "verifies the signature" do it "verifies the signature" do
other_sender = FactoryGirl.generate(:diaspora_id) other_sender = Fabricate.sequence(:diaspora_id)
other_key = OpenSSL::PKey::RSA.generate(512) other_key = OpenSSL::PKey::RSA.generate(512)
expect_callback(:fetch_public_key, other_sender).and_return(other_key) expect_callback(:fetch_public_key, other_sender).and_return(other_key)

View file

@ -25,7 +25,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :messages } let(:property) { :messages }
let(:wrong_values) { [nil] } let(:wrong_values) { [nil] }
let(:correct_values) { [[], [FactoryGirl.build(:message_entity)]] } let(:correct_values) { [[], [Fabricate(:message_entity)]] }
end end
end end
@ -33,8 +33,8 @@ module DiasporaFederation
# must not contain more than 20 participant handles # must not contain more than 20 participant handles
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :participants } let(:property) { :participants }
let(:wrong_values) { [Array.new(21) { FactoryGirl.generate(:diaspora_id) }.join(";")] } let(:wrong_values) { [Array.new(21) { Fabricate.sequence(:diaspora_id) }.join(";")] }
let(:correct_values) { [Array.new(20) { FactoryGirl.generate(:diaspora_id) }.join(";")] } let(:correct_values) { [Array.new(20) { Fabricate.sequence(:diaspora_id) }.join(";")] }
end end
end end
end end

View file

@ -21,11 +21,11 @@ module DiasporaFederation
describe "#poll_answers" do describe "#poll_answers" do
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :poll_answers } let(:property) { :poll_answers }
let(:wrong_values) { [nil, [FactoryGirl.attributes_for(:poll_answer_entity)]] } let(:wrong_values) { [nil, [Fabricate.attributes_for(:poll_answer_entity)]] }
let(:correct_values) { let(:correct_values) {
[ [
Array.new(2) { FactoryGirl.build(:poll_answer_entity) }, Array.new(2) { Fabricate(:poll_answer_entity) },
Array.new(5) { FactoryGirl.build(:poll_answer_entity) } Array.new(5) { Fabricate(:poll_answer_entity) }
] ]
} }
end end

View file

@ -22,7 +22,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target } let(:property) { :target }
let(:wrong_values) { [nil] } let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] } let(:correct_values) { [Fabricate(:related_entity)] }
end end
end end
end end

View file

@ -22,7 +22,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target } let(:property) { :target }
let(:wrong_values) { [nil] } let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] } let(:correct_values) { [Fabricate(:related_entity)] }
end end
end end
end end

View file

@ -1,5 +1,5 @@
describe Validation::Rule::DiasporaIdCount do describe Validation::Rule::DiasporaIdCount do
let(:id_str) { Array.new(3) { FactoryGirl.generate(:diaspora_id) }.join(";") } let(:id_str) { Array.new(3) { Fabricate.sequence(:diaspora_id) }.join(";") }
it "requires a parameter" do it "requires a parameter" do
validator = Validation::Validator.new({}) validator = Validation::Validator.new({})

View file

@ -22,7 +22,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target } let(:property) { :target }
let(:wrong_values) { [nil] } let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] } let(:correct_values) { [Fabricate(:related_entity)] }
end end
end end
end end

View file

@ -17,7 +17,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :photos } let(:property) { :photos }
let(:wrong_values) { [nil] } let(:wrong_values) { [nil] }
let(:correct_values) { [[], [FactoryGirl.build(:photo_entity)]] } let(:correct_values) { [[], [Fabricate(:photo_entity)]] }
end end
end end

View file

@ -19,7 +19,7 @@ require "rspec/rails"
require "webmock/rspec" require "webmock/rspec"
require "rspec/json_expectations" require "rspec/json_expectations"
# load factory girl factories # load factories
require "factories" require "factories"
# load test entities # load test entities
@ -74,7 +74,6 @@ RSpec.configure do |config|
expect_config.syntax = :expect expect_config.syntax = :expect
end end
config.include FactoryGirl::Syntax::Methods
config.use_transactional_fixtures = true config.use_transactional_fixtures = true
# load fixtures # load fixtures

View file

@ -11,7 +11,7 @@ FixtureBuilder.configure do |fbuilder|
# now declare objects # now declare objects
fbuilder.factory do fbuilder.factory do
FactoryGirl.create(:user, diaspora_id: "alice@localhost:3000") Fabricate(:user, diaspora_id: "alice@localhost:3000")
FactoryGirl.create(:user, diaspora_id: "bob@localhost:3000") Fabricate(:user, diaspora_id: "bob@localhost:3000")
end end
end end

View file

@ -121,7 +121,7 @@ end
shared_examples "a retraction" do shared_examples "a retraction" do
context "receive with no target found" do context "receive with no target found" do
let(:unknown_guid) { FactoryGirl.generate(:guid) } let(:unknown_guid) { Fabricate.sequence(:guid) }
let(:instance) { described_class.new(data.merge(target_guid: unknown_guid)) } let(:instance) { described_class.new(data.merge(target_guid: unknown_guid)) }
it "raises when no target is found" do it "raises when no target is found" do

View file

@ -1,6 +1,6 @@
def entity_stub(entity, data={}) def entity_stub(entity, data={})
OpenStruct.new(FactoryGirl.factory_by_name(entity).build_class.default_values OpenStruct.new(Fabricate.schematic(entity).options[:class_name].default_values
.merge(FactoryGirl.attributes_for(entity)).merge(data)) .merge(Fabricate.attributes_for(entity)).merge(data))
end end
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze
@ -39,7 +39,7 @@ shared_examples "a relayable validator" do
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :parent } let(:property) { :parent }
let(:wrong_values) { [nil] } let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] } let(:correct_values) { [Fabricate(:related_entity)] }
end end
end end
end end

View file

@ -94,7 +94,7 @@ DiasporaFederation.configure do |config|
on :fetch_public_entity do |entity_type, guid| on :fetch_public_entity do |entity_type, guid|
type = DiasporaFederation::Entities.const_get(entity_type).entity_name type = DiasporaFederation::Entities.const_get(entity_type).entity_name
FactoryGirl.build("#{type}_entity", guid: guid) Fabricate("#{type}_entity", guid: guid)
end end
on :fetch_person_url_to do |diaspora_id, path| on :fetch_person_url_to do |diaspora_id, path|