require 'spec_helper' require 'deface/dsl/context' describe Deface::DSL::Context do include_context "mock Rails.application" context '#create_override' do subject { context = Deface::DSL::Context.new('sample_name') } def override_should_be_created_with(expected_hash) expect(Deface::Override).to receive(:new).with hash_including(expected_hash.reverse_merge(:name => 'sample_name')) subject.create_override end it 'should use name passed in through initializer' do override_should_be_created_with(:name => 'sample_name') end it 'should use value set with #virtual_path' do subject.virtual_path('test/path') override_should_be_created_with(:virtual_path => 'test/path') end context 'actions' do Deface::DEFAULT_ACTIONS.each do |action| action = action.to_sym it "should use value set with ##{action}" do subject.send(action, "#{action}/selector") override_should_be_created_with(action => "#{action}/selector") end end it 'should generate a warning if two action values are specified' do subject.insert_top('selector') logger = double('logger') expect(Rails).to receive(:logger).and_return(logger) expect(logger).to receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple action methods have been called. The last one will be used.") subject.insert_bottom('selector') end it 'should use the last action that is specified' do allow(Rails).to receive_message_chain(:logger, :error) subject.insert_top('insert_top/selector') subject.insert_bottom('insert_bottom/selector') override_should_be_created_with(:insert_bottom => 'insert_bottom/selector') end end context 'sources' do Deface::DEFAULT_SOURCES.each do |source| source = source.to_sym it "should use value set with ##{source}" do subject.send(source, "#{source} value") override_should_be_created_with(source => "#{source} value") end end it 'should generate a warning if two sources are specified' do subject.partial('partial name') logger = double('logger') expect(Rails).to receive(:logger).and_return(logger) expect(logger).to receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple source methods have been called. The last one will be used.") subject.template('template/path') end it 'should use the last source that is specified' do allow(Rails).to receive_message_chain(:logger, :error) subject.partial('partial name') subject.template('template/path') override_should_be_created_with(:template => 'template/path') end end # * :original - String containing original markup that is being overridden. # If supplied Deface will log when the original markup changes, which helps highlight overrides that need # attention when upgrading versions of the source application. Only really warranted for :replace overrides. # NB: All whitespace is stripped before comparsion. it 'should use value set with #original' do subject.original('