Sha256: 72b383026a4764d494b8d51ab935ba44058096b9c45ded3c617ac1b24761bfa2

Contents?: true

Size: 1.79 KB

Versions: 20

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Praxis::Mapper::Resources::Callbacks do
  context 'callbacks' do
    let(:double_model) do
      SimpleModel.new(before_count: 0, after_count: 0, around_count: 0, name: '', force: false)
    end
    let(:resource) { SimpleResource.new(double_model) }
    context 'using functions with args and kwargs' do
      subject { resource.change_name('hi', force: true) }
      it 'before' do
        expect(subject.record.before_count).to eq(1) # 1 before hook
      end
      it 'after' do
        expect(subject.record.after_count).to eq(1) # 1 after hook
      end
      it 'around' do
        # 50, just for the only filter
        expect(subject.record.around_count).to eq(50)
      end
      after do
        # one for the before, the around filter, the actual method and the after filter
        expect(subject.record.name).to eq('hi-hi-hi-hi')
        expect(subject.record.force).to be_truthy
      end
    end

    context 'using functions with only kwargs' do
      subject { resource.update!(number: 1000) }
      it 'before' do
        expect(subject.record.before_count).to eq(1) # 1 before hook
      end
      it 'after' do
        expect(subject.record.after_count).to eq(1) # 1 after hook
      end
      it 'around' do
        # 1000 for the orig update+1 from before_count + 50+100 for the 2 around filters
        expect(subject.record.around_count).to eq(1151)
      end
    end

    context 'using functions only args' do
      subject { resource.argsonly('hi') }
      it 'around' do
        # 50, just for the only filter
        expect(subject.record.around_count).to eq(50)
      end
      after do
        # one for the the around filter and one for the actual methodr
        expect(subject.record.name).to eq('hi-hi')
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
praxis-2.0.0 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.40 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.39 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.38 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.37 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.36 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.35 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.34 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.33 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.32 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.31 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.30 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.29 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.28 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.27 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.26 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.25 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.24 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.23 spec/praxis/mapper/resources/callbacks_spec.rb
praxis-2.0.pre.22 spec/praxis/mapper/resources/callbacks_spec.rb