Sha256: b9a73e0bbe4ad29e35344b92d06fd5fa300bb285cfc3558eb2fabee1589f3ab9

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

# -*- coding: utf-8 -*-
require File.expand_path( File.join( File.dirname( __FILE__ ),
                                     'spec_helper.rb' ) )

require 'ixtlan/configuration/resource'
require 'ixtlan/configuration/serializer'
require 'ixtlan/configuration/filter'
require 'ixtlan/babel/factory'

describe Ixtlan::Configuration::Configuration do

  subject do
    c = Ixtlan::Configuration::Configuration.instance
    c.modified_by = root
    c.save
    c
  end

  let( :root ) do
    unless u = Ixtlan::UserManagement::User.first
      u = Ixtlan::UserManagement::User.create( :login => 'root',
                                               :name => 'Root',
                                               :updated_at => DateTime.now )
    end
    u
  end

  let( :factory ) { Ixtlan::Babel::Factory.new }

  it 'serializes' do
    expected = {
      "base_url"=>"http://localhost:3000",
      "audit_keep_logs"=>30,
      "errors_keep_dumps"=>30,
      "errors_base_path"=>"/errors",
      "errors_from_email"=>"no-reply@example.com",
      "errors_to_emails"=>"developer@example.com",
      "modified_by"=>{
        "id"=>1,
        "login"=>"root",
        "name"=>"Root"
      }
    }
    result = factory.new_serializer( subject ).to_hash
    result.delete("created_at").wont_be_nil
    result.delete("updated_at").wont_be_nil
    result.must_equal expected
  end

  it 'filters' do
    expected = {
      "base_url"=>"http://localhost:3000",
      "audit_keep_logs"=>30,
      "errors_keep_dumps"=>30,
      "errors_base_path"=>"/errors",
      "errors_from_email"=>"no-reply@example.com",
      "errors_to_emails"=>"developer@example.com"
    }
    json = factory.new_serializer( subject ).to_hash
    result = factory.new_filter( subject.class ).filter_it( json ).to_hash
    result[ :params ].must_equal expected
    result[ 'updated_at' ].sub( /\..*$/, '').must_equal subject.updated_at.to_s.sub( /\+.*$/, '')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ixtlan-configuration-0.2.2 spec/configaration_serializer_spec.rb
ixtlan-configuration-0.2.1 spec/configaration_serializer_spec.rb