require 'spec_helper' module Alchemy describe Admin::BaseHelper do context "maximum amount of images option" do subject { helper.max_image_count } before { helper.instance_variable_set('@options', options) } context "with max_images option set to emtpy string" do let(:options) { {max_images: ""} } it { is_expected.to eq(nil) } end context "with max_images option set to '1'" do let(:options) { {max_images: "1"} } it { is_expected.to eq(1) } end context "with maximum_amount_of_images option set to emtpy string" do let(:options) { {maximum_amount_of_images: ""} } it { is_expected.to eq(nil) } end context "with maximum_amount_of_images option set to '1'" do let(:options) { {maximum_amount_of_images: "1"} } it { is_expected.to eq(1) } end end describe "#merge_params" do before do allow(controller).to receive(:params).and_return({:first => '1', :second => '2'}) end it "returns a hash that contains the current params and additional params given as attributes" do expect(helper.merge_params(:third => '3', :fourth => '4')).to eq({:first => '1', :second => '2', :third => '3', :fourth => '4'}) end end describe "#merge_params_without" do before do allow(controller).to receive(:params).and_return({:first => '1', :second => '2'}) end it "can delete a single param" do expect(helper.merge_params_without(:second)).to eq({:first => '1'}) end it "can delete several params" do expect(helper.merge_params_without([:first, :second])).to eq({}) end it "can delete a param and add new params at the same time" do expect(helper.merge_params_without([:first], {:third => '3'})).to eq({:second => '2', :third => '3'}) end it "should not change params" do helper.merge_params_without([:first]) expect(controller.params).to eq({:first => '1', :second => '2'}) end end describe "#merge_params_only" do before do allow(controller).to receive(:params).and_return({:first => '1', :second => '2', :third => '3'}) end it "can keep a single param" do expect(helper.merge_params_only(:second)).to eq({:second => '2'}) end it "can keep several params" do expect(helper.merge_params_only([:first, :second])).to eq({:first => '1', :second => '2'}) end it "can keep a param and add new params at the same time" do expect(helper.merge_params_only([:first], {:third => '3'})).to eq({:first => '1', :third => '3'}) end it "should not change params" do helper.merge_params_only([:first]) expect(controller.params).to eq({:first => '1', :second => '2', :third => '3'}) end end describe '#toolbar_button' do context "with permission" do before { allow(helper).to receive(:can?).and_return(true) } it "renders a toolbar button" do expect(helper.toolbar_button( url: admin_dashboard_path )).to match /