Sha256: 6641dab81150f2274c989639d652f0a923c00b7f65f90528b2e501ee8121f27e

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Acfs::Resource::Dirty do
  let(:model) { MyUser.new }
  before do
    stub_request(:get, 'http://users.example.org/users/1')
      .to_return response id: 1, name: 'Anon', age: 12
    stub_request(:post, 'http://users.example.org/users')
      .to_return response id: 5, name: 'dhh', age: 12
  end

  it 'includes ActiveModel::Dirty' do
    model.is_a? ActiveModel::Dirty
  end

  describe '#changed?' do
    context 'after attribute change' do
      let(:user) { MyUser.new name: 'dhh' }

      it { expect(user).to be_changed }

      context 'and saving' do
        before { user.save }
        it { expect(user).to_not be_changed }
      end
    end

    context 'after model load' do
      let(:user) { MyUser.find 1 }
      before { user && Acfs.run }

      it { expect(user).to_not be_changed }
    end

    context 'after model new without attrs' do
      let(:user) { MyUser.new }

      it { expect(user).to_not be_changed }
    end

    context 'after model new with attrs' do
      let(:user) { MyUser.new name: 'Uschi' }

      it { expect(user).to be_changed }
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
acfs-1.3.2 spec/acfs/resource/dirty_spec.rb
acfs-1.3.1 spec/acfs/resource/dirty_spec.rb
acfs-1.3.0 spec/acfs/resource/dirty_spec.rb
acfs-1.2.1 spec/acfs/resource/dirty_spec.rb
acfs-0.50.0 spec/acfs/resource/dirty_spec.rb
acfs-1.2.0 spec/acfs/resource/dirty_spec.rb
acfs-0.49.1 spec/acfs/resource/dirty_spec.rb
acfs-1.1.1 spec/acfs/resource/dirty_spec.rb
acfs-0.49.0 spec/acfs/resource/dirty_spec.rb
acfs-1.1.0 spec/acfs/resource/dirty_spec.rb
acfs-0.48.2 spec/acfs/resource/dirty_spec.rb
acfs-1.0.1 spec/acfs/resource/dirty_spec.rb
acfs-0.48.1 spec/acfs/resource/dirty_spec.rb
acfs-1.0.0 spec/acfs/resource/dirty_spec.rb
acfs-0.48.0 spec/acfs/resource/dirty_spec.rb
acfs-0.47.0 spec/acfs/resource/dirty_spec.rb
acfs-0.46.0 spec/acfs/resource/dirty_spec.rb
acfs-0.45.0 spec/acfs/resource/dirty_spec.rb
acfs-0.44.0 spec/acfs/resource/dirty_spec.rb
acfs-0.43.2 spec/acfs/resource/dirty_spec.rb