2010-09-17 23:00:55 +02:00
|
|
|
# encoding: utf-8
|
|
|
|
require File.expand_path('../../spec_helper', __FILE__)
|
|
|
|
require File.join(FIXTURE_PATH, 'more', 'cat')
|
|
|
|
|
|
|
|
describe CouchRest::Model::Base do
|
|
|
|
|
|
|
|
before do
|
|
|
|
@class = Class.new(CouchRest::Model::Base)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.configure' do
|
|
|
|
it "should set a configuration parameter" do
|
|
|
|
@class.add_config :foo_bar
|
|
|
|
@class.configure do |config|
|
|
|
|
config.foo_bar = 'monkey'
|
|
|
|
end
|
|
|
|
@class.foo_bar.should == 'monkey'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.add_config' do
|
|
|
|
|
|
|
|
it "should add a class level accessor" do
|
|
|
|
@class.add_config :foo_bar
|
|
|
|
@class.foo_bar = 'foo'
|
|
|
|
@class.foo_bar.should == 'foo'
|
|
|
|
end
|
|
|
|
|
|
|
|
['foo', :foo, 45, ['foo', :bar]].each do |val|
|
|
|
|
it "should be inheritable for a #{val.class}" do
|
|
|
|
@class.add_config :foo_bar
|
|
|
|
@child_class = Class.new(@class)
|
|
|
|
|
|
|
|
@class.foo_bar = val
|
|
|
|
@class.foo_bar.should == val
|
|
|
|
@child_class.foo_bar.should == val
|
|
|
|
|
|
|
|
@child_class.foo_bar = "bar"
|
|
|
|
@child_class.foo_bar.should == "bar"
|
|
|
|
|
|
|
|
@class.foo_bar.should == val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it "should add an instance level accessor" do
|
|
|
|
@class.add_config :foo_bar
|
|
|
|
@class.foo_bar = 'foo'
|
|
|
|
@class.new.foo_bar.should == 'foo'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should add a convenient in-class setter" do
|
|
|
|
@class.add_config :foo_bar
|
|
|
|
@class.foo_bar "monkey"
|
|
|
|
@class.foo_bar.should == "monkey"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "General examples" do
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
@default_model_key = 'model'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it "should be possible to override on class using configure method" do
|
2010-10-22 15:39:12 +02:00
|
|
|
default_model_key = Cat.model_type_key
|
2010-09-17 23:00:55 +02:00
|
|
|
Cat.instance_eval do
|
2010-09-18 15:19:15 +02:00
|
|
|
model_type_key 'cat-type'
|
2010-09-17 23:00:55 +02:00
|
|
|
end
|
2010-10-22 15:39:12 +02:00
|
|
|
CouchRest::Model::Base.model_type_key.should eql(default_model_key)
|
2010-09-17 23:00:55 +02:00
|
|
|
Cat.model_type_key.should eql('cat-type')
|
|
|
|
cat = Cat.new
|
|
|
|
cat.model_type_key.should eql('cat-type')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|