require 'spec_helper'

describe Jdb::Resource::ResourceModel do

  let(:dummy1)              { ResourceDummy.new("X", "Y", "Z") }
  let(:dummy2)              { ResourceDummy.new("X", "Y", "Z") }
  let(:dummy3)              { ResourceDummy.new("A", "B", "C") }
  let(:d1_attrs)            { [:attr1, :attr2, :attr3] }
  let(:d1_attrs_with_vals)  { { attr1:'X', attr2:'Y', attr3: 'Z' } }

  describe '#attrs' do
    it 'gets attributes specified with' do
      expect(dummy1.attrs).to eq(d1_attrs)
    end
  end

  describe 'define_attr_getter_methods' do
    it 'defines getter methods for each `attr`' do
      expect { dummy1.attr1 }.to raise_error(NoMethodError)
      dummy1.define_attr_getter_methods
      expect(dummy1.attr1).to eq "X"
    end
  end

  describe 'define_attr_setter_methods' do
    it 'defines setter methods for each `attr`' do
      expect { dummy1.attr1 = "XXX" }.to raise_error(NoMethodError)
      dummy1.define_attr_setter_methods
      dummy1.attr1 = "XXX"
      expect(dummy1.attr1).to eq("XXX")
    end
  end

  describe '#uneq_attrs' do
    it 'returns an array of the (non-excluded) unequal attributes' do
      expect(dummy1.uneq_attrs(dummy3)).to eq(d1_attrs)
    end
  end

  describe '#attrs_eq?' do
    it 'returns true if all (non-excluded) attributes are equal' do
      expect(dummy1.attrs_eq?(dummy1)).to eq(true)
      expect(dummy1.attrs_eq?(dummy2)).to eq(true)
    end

    it 'returns false if any (non-excluded) attribute is unequal' do
      expect(dummy1.attrs_eq?(dummy3)).to eq(false)
    end
  end

end
