Sha256: a52b55d54beca5e22424c50f4ae3a4af70651e4136b786f9d46603e0c4f2b8fb

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require 'rails_helper'

RSpec.describe Attachy::Viewer, '.file_button' do
  let!(:method)  { :avatar }
  let!(:object)  { create :user }
  let!(:options) { { button: { html: { key: :value } } } }

  let!(:file) do
    allow(Cloudinary::Uploader).to receive(:remove_tag)

    create :file, attachable: object
  end

  subject { described_class.new method, object, options }

  before do
    allow(subject).to receive(:button_label) { '1' }
    allow(subject).to receive(:file_field)   { '2' }
    allow(subject).to receive(:hidden_field) { '3' }
  end

  describe 'default options' do
    it 'uses generic button options' do
      el = subject.file_button

      expect(el).to have_tag :div, with: { class: 'attachy__button', key: :value }
    end

    it 'builds a content based on button label, file field and hidden field' do
      el = subject.file_button

      expect(el).to have_tag :div do
        with_text '123'
      end
    end
  end

  context 'when :html is present' do
    let!(:html) { { key: :value } }

    it 'merges with default' do
      el = subject.file_button

      expect(el).to have_tag :div, with: { class: 'attachy__button', key: :value }
    end
  end

  context 'when a block is given' do
    let!(:html) { { key: :value } }

    it 'yields the :html options' do
      subject.file_button(html: html) do |htm|
        expect(htm).to eq(key: :value, class: :attachy__button)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attachy-0.1.2 spec/models/attachy/viewer/file_button_spec.rb
attachy-0.1.1 spec/models/attachy/viewer/file_button_spec.rb
attachy-0.1.0 spec/models/attachy/viewer/file_button_spec.rb