Skip to content

Commit

Permalink
Merge pull request #11 from sergey-kucher/manager_comments
Browse files Browse the repository at this point in the history
feature: create manager orders counter
  • Loading branch information
dsalahutdinov committed Mar 10, 2016
2 parents 8f460c1 + 9db4360 commit 2841de0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/treasury/processors/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
module Treasury
module Processors
class Base < ::CoreDenormalization::Processors::Base
def current_value(field_name = nil)
object_value(@object, field_name)
end

def object_value(l_object, field_name = nil)
value = if @data.key?(l_object)
@data[l_object][field_name || field.first_field]
else
field.raw_value(l_object, field_name)
end
log_event(:message => "get object #{l_object} value", :payload => value)
value
end

def form_value(value)
value
end
Expand Down
50 changes: 50 additions & 0 deletions spec/lib/treasury/processors/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# coding: utf-8

require 'spec_helper'

RSpec.describe ::Treasury::Processors::Base do
let(:instance) { described_class.new }

let(:object) { '2000' }
let(:data) do
{
'1000' => {count1: '50', count2: '100'},
'2000' => {count1: '550', count2: '600'}
}
end
let(:field) { double first_field: :count1 }

before do
instance.instance_variable_set(:@data, data)
instance.instance_variable_set(:@object, object)

allow(instance).to receive(:field).and_return(field)

allow(instance).to receive(:log_event)
end

describe '#current_value' do
it { expect(instance.current_value :count2).to eq '600' }
end

describe '#object_value' do
before do
allow(instance.field).to receive(:raw_value).with('3000', :count2).and_return('1050')
end

it do
expect(instance.object_value '1000', :count2).to eq '100'
expect(instance.object_value '1000').to eq '50'
expect(instance.object_value '2000').to eq '550'
expect(instance.object_value '3000', :count2).to eq '1050'
end
end

describe '#form_value' do
it { expect(instance.form_value '10').to eq '10' }
end

describe '#result_row' do
it { expect(instance.result_row '10').to eq '2000' => '10' }
end
end

0 comments on commit 2841de0

Please sign in to comment.