Generate default users only once and reset db after each test
This commit is contained in:
parent
696f50f40d
commit
1f067c62a7
4 changed files with 27 additions and 3 deletions
14
spec/support/fixture_builder.rb
Normal file
14
spec/support/fixture_builder.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -19,5 +19,9 @@ class Entity
|
|||
def database
|
||||
@database ||= Hash.new({})
|
||||
end
|
||||
|
||||
def reset_database
|
||||
@database = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue