spec/model/model_spec.rb in ronin-0.3.0 vs spec/model/model_spec.rb in ronin-1.0.0.pre1

- old
+ new

@@ -1,67 +1,75 @@ +require 'model/spec_helper' +require 'model/models/basic_model' +require 'model/models/custom_model' + require 'ronin/model/model' -require 'spec_helper' -require 'model/classes/basic_model' -require 'model/classes/custom_model' - describe Model do + subject { BasicModel } + + let(:custom_model) { CustomModel } + before(:all) do - BasicModel.auto_migrate! - CustomModel.auto_migrate! + subject.auto_migrate! end it "should have a default repository name" do - BasicModel.default_repository_name.should == Model::REPOSITORY_NAME + subject.default_repository_name.should == :default end it "should allow creating new instances of the model" do - resource = BasicModel.new(:name => 'joe') + resource = subject.new(:name => 'joe') resource.name.should == 'joe' end it "should call initialize when creating new instances of the model" do - resource = CustomModel.new(:name => 'joe') + resource = custom_model.new(:name => 'joe') resource.name.should == 'joe' resource.var.should == 2 end - it "should still call initialize when loading from the database" do - CustomModel.create(:name => 'bob') + it "should call initialize when creating a new resource" do + resource = custom_model.create!(:name => 'jim') - resource = CustomModel.first + resource.name.should == 'jim' + resource.var.should == 2 + end + + it "should call initialize when loading from the database" do + custom_model.create!(:name => 'bob') + + resource = custom_model.first(:name => 'bob') resource.name.should == 'bob' resource.var.should == 2 end describe "humanize_attributes" do - before(:all) do - @resource = BasicModel.new(:name => 'joe', :age => 21) - end + let(:resource) { subject.new(:name => 'joe', :age => 21) } it "should humanize the attributes of a model" do - @resource.humanize_attributes.should == { + resource.humanize_attributes.should == { 'Name' => 'joe', 'Age' => '21' } end it "should exclude certain attributes to humanize" do - @resource.humanize_attributes(:exclude => [:name]).should == { + resource.humanize_attributes(:exclude => [:name]).should == { 'Age' => '21' } end it "should filter out nil values" do - resource = BasicModel.new(:name => 'joe') + resource.age = nil resource.humanize_attributes.should == {'Name' => 'joe'} end it "should filter out empty values" do - resource = BasicModel.new(:name => '', :age => 21) + resource.name = '' resource.humanize_attributes.should == {'Age' => '21'} end end end