Skip to content

Commit

Permalink
Merge pull request #43 from artofhuman/extract-sources
Browse files Browse the repository at this point in the history
fix: add raise_no_implemented method to raise treasury error
  • Loading branch information
artofhuman authored Apr 17, 2017
2 parents 5ba4a34 + 570ec1d commit ee26477
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/treasury/fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class Base
#
define_callbacks :data_changed

def self.raise_no_implemented(accessor_type, params)
raise Treasury::Fields::Errors::NoAccessor.new(self, accessor_type, params)
end

def self.create_by_class(klass, field_model = Treasury::Models::Field.find_by_field_class(klass.to_s))
raise Errors::UnknownFieldClassError if field_model.nil?
return klass.to_s.constantize.new(field_model)
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/treasury/fields/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def data_changed_callback; end

class TreasuryFieldsBase < Treasury::Fields::Base
include FieldCallback

def self.value_as_integer(params)
raise_no_implemented(:integer, params)
end
end

describe TreasuryFieldsBase do
Expand All @@ -35,4 +39,11 @@ class TreasuryFieldsBase < Treasury::Fields::Base
subject.send(:data_changed, chaged_objects)
end
end

describe 'raise_no_implemented' do
it do
expect { described_class.value_as_integer({}) }
.to raise_error(Treasury::Fields::Errors::NoAccessor)
end
end
end

0 comments on commit ee26477

Please sign in to comment.