Sha256: 0237db27b4a004a0a9db538f58e359b79d1196b2846065e82c15a0249d05d114

Contents?: true

Size: 1.78 KB

Versions: 7

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'
require 'model/models/basic_model'
require 'model/models/custom_model'

require 'ronin/model/model'

describe Model do
  subject { BasicModel }

  let(:custom_model) { CustomModel }

  before(:all) { subject.auto_migrate! }

  it "should have a default repository name" do
    subject.default_repository_name.should == :default
  end

  it "should allow creating new instances of the model" do
    resource = subject.new(:name => 'joe')

    resource.name.should == 'joe'
  end

  it "should call initialize when creating new instances of the model" do
    resource = custom_model.new(:name => 'joe')

    resource.name.should == 'joe'
    resource.var.should == 2
  end

  it "should call initialize when creating a new resource" do
    resource = custom_model.create!(:name => 'jim')

    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
    let(:resource) { subject.new(:name => 'joe', :age => 21) }

    it "should humanize the attributes of a model" do
      resource.humanize_attributes.should == {
        'Name' => 'joe',
        'Age' => '21'
      }
    end

    it "should exclude certain attributes to humanize" do
      resource.humanize_attributes(:exclude => [:name]).should == {
        'Age' => '21'
      }
    end

    it "should filter out nil values" do
      resource.age = nil

      resource.humanize_attributes.should == {'Name' => 'joe'}
    end

    it "should filter out empty values" do
      resource.name = ''

      resource.humanize_attributes.should == {'Age' => '21'}
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ronin-1.5.0 spec/model/model_spec.rb
ronin-1.5.0.rc2 spec/model/model_spec.rb
ronin-1.5.0.rc1 spec/model/model_spec.rb
ronin-1.4.1 spec/model/model_spec.rb
ronin-1.4.0 spec/model/model_spec.rb
ronin-1.4.0.rc2 spec/model/model_spec.rb
ronin-1.4.0.rc1 spec/model/model_spec.rb