Generate default users only once and reset db after each test

This commit is contained in:
Benjamin Neff 2017-04-05 00:35:30 +02:00
parent 696f50f40d
commit 1f067c62a7
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
4 changed files with 27 additions and 3 deletions

View file

@ -0,0 +1,14 @@
# set default users as initial database for each test
RSpec.configure do |config|
config.before(:suite) do
Person.reset_database
Fabricate(:user, diaspora_id: "alice@localhost:3000")
Fabricate(:user, diaspora_id: "bob@localhost:3000")
Person.init_database = Person.database
end
config.after(:each) do
Entity.reset_database
Person.reset_database
end
end

View file

@ -1,10 +1,10 @@
# default users
def alice
@alice ||= Fabricate(:user, diaspora_id: "alice@localhost:3000")
@alice ||= Person.find_by(diaspora_id: "alice@localhost:3000")
end
def bob
@bob ||= Fabricate(:user, diaspora_id: "bob@localhost:3000")
@bob ||= Person.find_by(diaspora_id: "bob@localhost:3000")
end
# callback expectation helper

View file

@ -19,5 +19,9 @@ class Entity
def database
@database ||= Hash.new({})
end
def reset_database
@database = nil
end
end
end

View file

@ -30,13 +30,19 @@ class Person
end
class << self
attr_writer :init_database
def find_by(opts)
return database[:diaspora_id][opts[:diaspora_id]] if opts[:diaspora_id]
database[:guid][opts[:guid]]
end
def database
@database ||= {diaspora_id: {}, guid: {}}
@database ||= @init_database || {diaspora_id: {}, guid: {}}
end
def reset_database
@database = nil
end
end
end