Sha256: 4c1afe9e5bc4e08e5ac654ac4594387816b4e3c2388b0c796475e7e8cd24b7ef

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'ronin/model/model'

require 'spec_helper'
require 'model/classes/basic_model'
require 'model/classes/custom_model'

describe Model do
  before(:all) do
    BasicModel.auto_migrate!
    CustomModel.auto_migrate!
  end

  it "should have a default repository name" do
    BasicModel.default_repository_name.should == Model::REPOSITORY_NAME
  end

  it "should allow creating new instances of the model" do
    resource = BasicModel.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.name.should == 'joe'
    resource.var.should == 2
  end

  it "should still call initialize when loading from the database" do
    CustomModel.create(:name => 'bob')

    resource = CustomModel.first
    resource.name.should == 'bob'
    resource.var.should == 2
  end

  describe "humanize_attributes" do
    before(:all) do
      @resource = BasicModel.new(:name => 'joe', :age => 21)
    end

    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 = BasicModel.new(:name => 'joe')

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

    it "should filter out empty values" do
      resource = BasicModel.new(:name => '', :age => 21)

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ronin-0.3.0 spec/model/model_spec.rb