spec/models/base_spec.rb in pupa-0.0.7 vs spec/models/base_spec.rb in pupa-0.0.8
- old
+ new
@@ -16,13 +16,19 @@
},
},
},
},
}
- attr_accessor :name, :label, :founding_date, :inactive, :label_id, :manager_id, :links
+
+ attr_accessor :label, :founding_date, :inactive, :label_id, :manager_id, :links
+ attr_reader :name
foreign_key :label_id, :manager_id
foreign_object :label
+
+ def name=(name)
+ @name = name
+ end
end
end
let :properties do
{name: 'Moderat', label: {name: 'Mute'}, inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
@@ -30,29 +36,37 @@
let :object do
Music::Band.new(properties)
end
- describe '#attr_accessor' do
+ describe '.attr_accessor' do
it 'should add properties' do
- Music::Band.properties.to_a.should == [:_id, :_type, :extras, :name, :label, :founding_date, :inactive, :label_id, :manager_id, :links]
+ [:_id, :_type, :extras, :label, :founding_date, :inactive, :label_id, :manager_id, :links].each do |property|
+ Music::Band.properties.to_a.should include(property)
+ end
end
end
- describe '#foreign_key' do
+ describe '.attr_reader' do
+ it 'should add properties' do
+ Music::Band.properties.to_a.should include(:name)
+ end
+ end
+
+ describe '.foreign_key' do
it 'should add foreign keys' do
Music::Band.foreign_keys.to_a.should == [:label_id, :manager_id]
end
end
- describe '#foreign_object' do
+ describe '.foreign_object' do
it 'should add foreign objects' do
Music::Band.foreign_objects.to_a.should == [:label]
end
end
- describe '#schema=' do
+ describe '.schema=' do
let :klass_with_absolute_path do
Class.new(Pupa::Base) do
self.schema = '/path/to/schema.json'
end
end
@@ -80,14 +94,16 @@
},
}
end
it 'should accept an absolute path' do
- klass_with_absolute_path.json_schema.should == '/path/to/schema.json'
+ File.should_receive(:read).and_return('{}')
+ klass_with_absolute_path.json_schema.should == '{}'
end
it 'should accept a relative path' do
- klass_with_relative_path.json_schema.should == File.expand_path(File.join('..', '..', 'schemas', 'schema.json'), __dir__)
+ File.should_receive(:read).and_return('{}')
+ klass_with_relative_path.json_schema.should == '{}'
end
end
describe '#initialize' do
it 'should set the _type' do