Commit 1d224982 authored by Mark Lapierre's avatar Mark Lapierre

Fix Resource attribute bug

Allow Resources to have the same attribute name
but different attribute values
parent 75b1837d
...@@ -116,23 +116,13 @@ module QA ...@@ -116,23 +116,13 @@ module QA
end end
private_class_method :evaluator private_class_method :evaluator
def self.dynamic_attributes
const_get(:DynamicAttributes)
rescue NameError
mod = const_set(:DynamicAttributes, Module.new)
include mod
mod
end
class DSL class DSL
def initialize(base) def initialize(base)
@base = base @base = base
end end
def attribute(name, &block) def attribute(name, &block)
@base.dynamic_attributes.module_eval do @base.module_eval do
attr_writer(name) attr_writer(name)
define_method(name) do define_method(name) do
......
...@@ -213,6 +213,42 @@ describe QA::Resource::Base do ...@@ -213,6 +213,42 @@ describe QA::Resource::Base do
.to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.") .to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.")
end end
end end
context 'when multiple resources have the same attribute name' do
let(:base) do
Class.new(QA::Resource::Base) do
def fabricate!
'any'
end
def self.current_url
'http://stub'
end
end
end
let(:first_resource) do
Class.new(base) do
attribute :test do
'first block'
end
end
end
let(:second_resource) do
Class.new(base) do
attribute :test do
'second block'
end
end
end
it 'has unique attribute values' do
first_result = first_resource.fabricate!(resource: first_resource.new)
second_result = second_resource.fabricate!(resource: second_resource.new)
expect(first_result.test).to eq 'first block'
expect(second_result.test).to eq 'second block'
end
end
end end
describe '#web_url' do describe '#web_url' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment