Sha256: f5264842cc949971a2094335037da3070b792658bc83e993e5902a1c4fa9f46d

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'
require 'ardm/property/support/dirty_minder'

describe Ardm::Property::DirtyMinder,'set!' do

  let(:property_class) do
    Class.new(Ardm::Property::Object) do
    end
  end

  let(:model) do
    property_class = self.property_class
    Class.new(Ardm::Record) do
      self.table_name = 'api_users'

      property :id, Ardm::Property::Serial
      property :name, property_class
    end
  end

  let(:resource) { model.new }

  let(:object) { model.properties[:name] }

  subject { object.set!(resource,value) }

  shared_examples_for 'a non hooked value' do
    it 'should not extend value with hook' do
      expect(object.get!(resource)).not_to be_kind_of(Ardm::Property::DirtyMinder::Hooker)
    end
  end

  shared_examples_for 'a hooked value' do
    it 'should extend value with hook', pending: true do
      expect(object.get!(resource)).to be_kind_of(Ardm::Property::DirtyMinder::Hooker)
    end
  end

  before do
    subject
  end

  context 'when setting nil' do
    let(:value) { nil }
    it_should_behave_like 'a non hooked value'
  end

  context 'when setting a String' do
    let(:value) { "The fred" }
    it_should_behave_like 'a non hooked value'
  end

  context 'when setting an Array' do
    let(:value) { ["The fred"] }
    it_should_behave_like 'a hooked value'
  end

  context 'when setting a Hash' do
    let(:value) { {"The" => "fred"} }
    it_should_behave_like 'a hooked value'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ardm-0.1.0 spec/unit/dirty_minder_spec.rb