Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
fix test, rename, always include comatablity
Browse files Browse the repository at this point in the history
Fixed tests (must have explicit pavlov_options)
rename in tests interactor => old interactor
always compatability for now
  • Loading branch information
jjoos committed Jul 25, 2013
1 parent 02d0588 commit e3b20a3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/pavlov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 7 additions & 2 deletions lib/pavlov/alpha_compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/pavlov/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/integration/alpha_compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ 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
end

class Interactors::ShoutyGreeting
include Pavlov::Interactor
arguments

attribute :pavlov_options, Hash, default: {}

def authorized?; true; end
def execute
"OHAI, #{old_query :find_uppercase_name}"
Expand Down
10 changes: 5 additions & 5 deletions spec/pavlov/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e3b20a3

Please sign in to comment.