require 'rails_helper' describe DomFor do it 'includes in ActiveView::Base' do expect(ActionView::Base.ancestors).to include(DomFor) end context '#dom_for' do it 'returns span tag' do expect(helper.dom_for(User, tag: :span)).to eq '' end context 'with model' do it 'returns div without nested tags' do expect(helper.dom_for(User)).to eq '
' end it 'returns div with data-action attribute' do expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' }) expect(helper.dom_for(User)).to eq '
' end it 'returns div for the new user' do @user = User.new(name: 'test') expect(helper.request).to receive(:path_parameters).and_return({ action: 'new' }) expect(helper.dom_for(User)).to eq '
' end it 'returns div for the new user without request' do @user = User.new(name: 'test') expect(helper.dom_for(User)).to eq '
' end it 'returns div for the saved user' do @user = User.create(name: 'test') expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' }) expect( helper.dom_for(User) ).to eq '
' end it 'returns div with the additional data-attributes' do @user = User.create(name: 'test') expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' }) expect( helper.dom_for(User, admin: true) ).to eq '
' end it 'returns div with nested tags' do @user = User.create(name: 'test') expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' }) expect( helper.dom_for(User, admin: true) { helper.tag(:span) } ).to eq '
' end end context 'with record' do it 'returns div for the new user' do expect(helper.dom_for(User.new)).to eq '
' end it 'returns div without nested tags' do user = User.create(name: 'test') expect(helper.dom_for(user)).to eq '
' end it 'returns div with nested tags' do user = User.create(name: 'test') expect( helper.dom_for(user) { helper.tag(:span) } ).to eq '
' end it 'returns div with the additional data-attributes' do user = User.create(name: 'test') expect( helper.dom_for(user, admin: true) { helper.tag(:span) } ).to eq '
' end end end end