Sha256: 2ab3deaf20db28c3676bc9d65f2830a273a4611d4e238d87e719b1f5df7cf690

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

module Happy
  describe Controller::Configurable do
    class TestController < Happy::Controller
      set :foo, 'bar'
    end

    describe '.set' do
      it 'sets a class-level option' do
        TestController.options[:foo].should == 'bar'
      end
    end

    describe '#set' do
      before do
        @instance = TestController.new
        @instance.set :foo, 'baz'
      end

      it 'sets an instance-level option, overriding the class default' do
        @instance.options[:foo].should == 'baz'
      end

      it "doesn't modify the class-level default option" do
        TestController.options[:foo].should == 'bar'
      end
    end

    describe 'class-level options' do
      it 'are the defaults for instance-level options' do
        TestController.new.options[:foo].should == 'bar'
      end
    end

    describe 'cascading options' do
      class OuterController < Controller
        set :views, './foo/'
        set :foo, 'bar'
      end

      class InnerController < Controller
      end

      it "are copied from the parent controller if necessary" do
        @instance = InnerController.new(OuterController.new)
        @instance.options[:views].should == './foo/'
        @instance.options[:foo].should be_nil
      end
    end

    describe 'options passed to the initializer' do
      it "override default options" do
        @instance = TestController.new({}, :foo => 'baz')
        @instance.options[:foo].should == 'baz'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
happy-0.1.0.pre25 spec/controller/configurable_spec.rb
happy-0.1.0.pre24 spec/controller/configurable_spec.rb
happy-0.1.0.pre23 spec/controller/configurable_spec.rb
happy-0.1.0.pre22 spec/controller/configurable_spec.rb
happy-0.1.0.pre21 spec/controller/configurable_spec.rb