diff options
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | lib/boot/bootstrap_container.rb | 43 | ||||
| -rw-r--r-- | lib/boot/routes.rb | 3 | ||||
| -rw-r--r-- | lib/orm/unit_of_work.rb | 5 | ||||
| -rw-r--r-- | lib/orm/unit_of_work_factory.rb | 4 | ||||
| -rw-r--r-- | spec/specs/orm/unit_of_work_factory_spec.rb | 2 | ||||
| -rw-r--r-- | spec/specs/orm/unit_of_work_spec.rb | 2 |
7 files changed, 36 insertions, 25 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index ee7aa37..cf1f489 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,7 +16,7 @@ GEM gem_plugin (0.2.3) headless (1.0.1) httpauth (0.2.0) - humble (0.0.1374368890) + humble (0.0.1374372435) sequel jwt (0.1.8) multi_json (>= 1.5) diff --git a/lib/boot/bootstrap_container.rb b/lib/boot/bootstrap_container.rb index ed4eed0..93b3892 100644 --- a/lib/boot/bootstrap_container.rb +++ b/lib/boot/bootstrap_container.rb @@ -6,29 +6,36 @@ class BootstrapContainer @container = container end def run + configuration = Humble::Configuration.new(DatabaseConfiguration.new.connection_string) + configuration.add(UserMapping.new) + configuration.add(ProductMapping.new) + session_factory = configuration.build_session_factory + @container.register(:command_registry) { Booty::RouteRegistry.new }.as_singleton @container.register(:front_controller) { @container.build(Booty::FrontController) } @container.register(:view_engine) do Booty::ViewEngine.new(:root_path => 'lib/commands', :master => 'master') end @container.register(:products_repository) do - Repository.new(:products, @container.resolve(:database_gateway), DataMapper.new(Product)) + #Repository.new(:products, @container.resolve(:database_gateway), DataMapper.new(Product)) + HumbleRepository.new(@container.resolve(:context).item_for(@container.resolve(:key)), Product) end @container.register(:users_repository) do - Repository.new(:users, @container.resolve(:database_gateway), DataMapper.new(User)) - end - @container.register(:database_gateway) do - @container.build(DatabaseGateway) - end - @container.register(:database_connection_factory) do - DatabaseConnectionFactory.new(@container.resolve(:database_configuration), @container.resolve(:database_connection_provider)) - end - @container.register(:database_configuration) do - DatabaseConfiguration.new - end - @container.register(:database_connection_provider) do - SequelConnectionProvider.new - end + #Repository.new(:users, @container.resolve(:database_gateway), DataMapper.new(User)) + HumbleRepository.new(@container.resolve(:context).item_for(@container.resolve(:key)), User) + end + #@container.register(:database_gateway) do + #@container.build(DatabaseGateway) + #end + #@container.register(:database_connection_factory) do + #DatabaseConnectionFactory.new(@container.resolve(:database_configuration), @container.resolve(:database_connection_provider)) + #end + #@container.register(:database_configuration) do + #DatabaseConfiguration.new + #end + #@container.register(:database_connection_provider) do + #SequelConnectionProvider.new + #end @container.register(:unit_of_work_interceptor) do @container.build(UnitOfWorkInterceptor) end @@ -40,11 +47,11 @@ class BootstrapContainer SimpleContext.new end.as_singleton @container.register(:session_factory) do - @container.build(SessionFactory) - end + session_factory + end.as_singleton @container.register(:key) do Key.new("database.session") - end + end.as_singleton @container.register(:current_user_interceptor) do @container.build(CurrentUserInterceptor) end diff --git a/lib/boot/routes.rb b/lib/boot/routes.rb index 027c5f4..8e5f67f 100644 --- a/lib/boot/routes.rb +++ b/lib/boot/routes.rb @@ -9,7 +9,8 @@ module Booty def run @registry.register(Assets::AssetCommand.new) - @registry.register(route_to(Dashboard::IndexCommand, [@container.resolve(:current_user_interceptor)])) + #@registry.register(route_to(Dashboard::IndexCommand, [@container.resolve(:current_user_interceptor)])) + @registry.register(route_to(Dashboard::IndexCommand)) @registry.register(route_to(Products::IndexCommand)) @registry.register(route_to(Products::NewCommand)) @registry.register(route_to(Products::CreateCommand)) diff --git a/lib/orm/unit_of_work.rb b/lib/orm/unit_of_work.rb index 468a04e..fc2ef96 100644 --- a/lib/orm/unit_of_work.rb +++ b/lib/orm/unit_of_work.rb @@ -4,13 +4,16 @@ class UnitOfWork @context = context @key = key end + def run(&block) - @session.run(&block) + @session.begin_transaction(&block) end + def dispose @context.remove(@key) @session.dispose end + def self.create(factory, &block) unit_of_work = factory.create begin diff --git a/lib/orm/unit_of_work_factory.rb b/lib/orm/unit_of_work_factory.rb index cd9926d..d6b1b2a 100644 --- a/lib/orm/unit_of_work_factory.rb +++ b/lib/orm/unit_of_work_factory.rb @@ -6,13 +6,13 @@ class UnitOfWorkFactory end def create - @context.contains?(@key) ? NullUnitOfWork.new : create_unit_of_work + @context.contains?(@key) ? NullUnitOfWork.new : create_unit_of_work end private def create_unit_of_work - session = @session_factory.create + session = @session_factory.create_session @context.add(@key, session) UnitOfWork.new(session, @context, @key) end diff --git a/spec/specs/orm/unit_of_work_factory_spec.rb b/spec/specs/orm/unit_of_work_factory_spec.rb index 38dad71..7be58eb 100644 --- a/spec/specs/orm/unit_of_work_factory_spec.rb +++ b/spec/specs/orm/unit_of_work_factory_spec.rb @@ -8,7 +8,7 @@ describe UnitOfWorkFactory do context "when creating a new unit of work" do let(:session) { "session" } - before { session_factory.stub(:create).and_return(session) } + before { session_factory.stub(:create_session).and_return(session) } context "when there is no running session" do before { application_context.stub(:contains?).with(key).and_return(false) } diff --git a/spec/specs/orm/unit_of_work_spec.rb b/spec/specs/orm/unit_of_work_spec.rb index 3ed5563..685f8a9 100644 --- a/spec/specs/orm/unit_of_work_spec.rb +++ b/spec/specs/orm/unit_of_work_spec.rb @@ -13,7 +13,7 @@ describe UnitOfWork do end it "should forward the block to the session" do - session.should have_received(:run) + session.should have_received(:begin_transaction) end end context "when ending a unit of work" do |
