Skip to content
Snippets Groups Projects
Commit 04e8c1cc authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

move repositories models to app/repositories and abstract the commom behavior for lib/repository

parent 00bb2c20
No related branches found
No related tags found
No related merge requests found
# the RepositoryEnvironments class holds the repository for each environment # the Environments class holds the repository for each environment
class RepositoryEnvironments class Repository::Environments
def self.create(env) def self.create(env)
environments[env] = Repository.new environments[env] = Repository::Repository.new
yield(environments[env]) if block_given? yield(environments[env]) if block_given?
end end
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# production_repository = Repository.new # production_repository = Repository.new
# production_repository.register :user, Repositories::OrientDB::UserRepository.new # production_repository.register :user, Repositories::OrientDB::UserRepository.new
# production_repository.for(:user).create!(name: 'mauricio', email: 'mgg12@inf.ufpr.br') # production_repository.for(:user).create!(name: 'mauricio', email: 'mgg12@inf.ufpr.br')
class Repository class Repository::Repository
def register(type, repository) def register(type, repository)
repositories[type] = repository repositories[type] = repository
......
require 'test_helper' require 'test_helper'
require 'test_model_repository' require 'test_model_repository'
class RepositoryEnvironmentsTest < ActiveSupport::TestCase class Repository::EnvironmentsTest < ActiveSupport::TestCase
def setup def setup
RepositoryEnvironments.create :test_env do |repository| Environments.create :test_env do |repository|
repository.register :test_model, TestModelRepository.new repository.register :test_model, TestModelRepository.new
end end
end end
test 'can create a repositories inside env' do test 'can create a repositories inside env' do
RepositoryEnvironments.create :test_specific_env do |repository| Environments.create :test_specific_env do |repository|
repository.register :test_model, TestModelRepository.new repository.register :test_model, TestModelRepository.new
end end
assert_count 1, RepositoryEnvironments.fetch(:test_specific_env).repositories assert_count 1, Environments.fetch(:test_specific_env).repositories
end end
test 'select a repository by environment' do test 'select a repository by environment' do
assert RepositoryEnvironments.fetch(:test_env).for(:test_model).working? assert Environments.fetch(:test_env).for(:test_model).working?
end end
end end
\ No newline at end of file
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment