From e3b20a3dcbb9e3bad17af402b175860fa6259e8a Mon Sep 17 00:00:00 2001 From: jjoos Date: Thu, 25 Jul 2013 14:44:00 +0200 Subject: [PATCH] fix test, rename, always include comatablity Fixed tests (must have explicit pavlov_options) rename in tests interactor => old interactor always compatability for now --- lib/pavlov.rb | 1 + lib/pavlov/alpha_compatibility.rb | 9 +++++++-- lib/pavlov/helpers.rb | 7 ++++++- spec/integration/alpha_compatibility_spec.rb | 8 ++++++-- spec/pavlov/helpers_spec.rb | 10 +++++----- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/pavlov.rb b/lib/pavlov.rb index 5d3c05b..cd2807f 100644 --- a/lib/pavlov.rb +++ b/lib/pavlov.rb @@ -38,3 +38,4 @@ def self.query command_name, *args require_relative 'pavlov/query' require_relative 'pavlov/interactor' require_relative 'pavlov/version' +require_relative 'pavlov/alpha_compatibility' diff --git a/lib/pavlov/alpha_compatibility.rb b/lib/pavlov/alpha_compatibility.rb index acb55cb..484baeb 100644 --- a/lib/pavlov/alpha_compatibility.rb +++ b/lib/pavlov/alpha_compatibility.rb @@ -24,8 +24,13 @@ def self.old_query command_name, *args def self.arguments_to_attributes(operation_class, arguments) attribute_keys = operation_class.attribute_set.map(&:name) - attributes_and_arguments = attribute_keys.zip(arguments) - Hash[attributes_and_arguments] + + # TODO: this can be done so much better, but I don't know how. + hash={} + arguments.each_with_index do |value, index| + hash[attribute_keys[index].to_sym] = value + end + return hash end module Helpers diff --git a/lib/pavlov/helpers.rb b/lib/pavlov/helpers.rb index d73c23e..7107d04 100644 --- a/lib/pavlov/helpers.rb +++ b/lib/pavlov/helpers.rb @@ -23,7 +23,12 @@ def pavlov_options def add_pavlov_options hash if pavlov_options != {} hash ||= {} - hash[:pavlov_options] = pavlov_options.merge(hash[:pavlov_options]) + + if hash.has_key? 'pavlov_options' + hash[:pavlov_options] = pavlov_options.merge(hash[:pavlov_options]) + else + hash[:pavlov_options] = pavlov_options + end end hash end diff --git a/spec/integration/alpha_compatibility_spec.rb b/spec/integration/alpha_compatibility_spec.rb index 103f51f..8698eae 100644 --- a/spec/integration/alpha_compatibility_spec.rb +++ b/spec/integration/alpha_compatibility_spec.rb @@ -40,7 +40,9 @@ def pavlov_options stub_const "Interactors", Module.new class Queries::FindUppercaseName include Pavlov::Query - arguments + + attribute :pavlov_options, Hash, default: {} + def execute pavlov_options[:current_user].name.upcase end @@ -48,7 +50,9 @@ def execute class Interactors::ShoutyGreeting include Pavlov::Interactor - arguments + + attribute :pavlov_options, Hash, default: {} + def authorized?; true; end def execute "OHAI, #{old_query :find_uppercase_name}" diff --git a/spec/pavlov/helpers_spec.rb b/spec/pavlov/helpers_spec.rb index 41f2fba..d2e737e 100644 --- a/spec/pavlov/helpers_spec.rb +++ b/spec/pavlov/helpers_spec.rb @@ -8,12 +8,12 @@ include Pavlov::Helpers def test - interactor :interactor_name, 'argument1', 'argument2' + old_interactor :interactor_name, 'argument1', 'argument2' end end instance = dummy_class.new - Pavlov.should_receive(:interactor) + Pavlov.should_receive(:old_interactor) .with(:interactor_name, 'argument1', 'argument2') instance.test @@ -29,12 +29,12 @@ def pavlov_options end def test - interactor :interactor_name, 'argument1', 'argument2' + old_interactor :interactor_name, 'argument1', 'argument2' end end instance = dummy_class.new - - Pavlov.should_receive(:interactor) + + Pavlov.should_receive(:old_interactor) .with(:interactor_name, 'argument1', 'argument2', hash) instance.test