Sha256: 5ef40af5b4d65f06a5c2872eb89c6a7c3cfcd29bb43e170ad3ff612339c75750

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

class DummyHelper
  include Attachy::ViewHelper
end

RSpec.describe DummyHelper, '.attachy' do
  let!(:method)  { :avatar }
  let!(:options) { { key: :value } }
  let!(:object)  { create :user }
  let!(:helper)  { DummyHelper.new }
  let!(:viewer)  { double Attachy::Viewer, field: :field }

  context 'with no block' do
    before do
      allow(Attachy::Viewer).to receive(:new).with(method, object, options, helper) { viewer }
    end

    it 'calls field from viewer' do
      expect(helper.attachy(method, object, options, nil)).to eq :field
    end
  end

  context 'with block' do
    let!(:block) { proc { |v| expect(v.field).to eq :field } }

    before do
      allow(Attachy::Viewer).to receive(:new).with(method, object, options, helper) { viewer }
    end

    it 'delegates to view helper with block' do
      helper.attachy method, object, options, block
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
attachy-0.4.1 spec/helpers/attachy/attachy_spec.rb
attachy-0.4.0 spec/helpers/attachy/attachy_spec.rb
attachy-0.3.0 spec/helpers/attachy/attachy_spec.rb
attachy-0.2.0 spec/helpers/attachy/attachy_spec.rb