Sha256: e982ec542bf0f3f0a91af3bc36a465025caac68e08e94aed8e0672f9022b09ec

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# coding: utf-8
require "spec_helper"
require "gettext_i18n_rails/model_attributes_finder"

if Rails::VERSION::MAJOR > 2
  module Test
    class Application < Rails::Application
    end
  end
end

describe GettextI18nRails::ModelAttributesFinder do
  let(:finder) { GettextI18nRails::ModelAttributesFinder.new }

  before do
    Rails.application rescue nil
  end

  # Rails < 3.0 doesn't have DescendantsTracker. 
  # Instead of iterating over ObjectSpace (slow) the decision was made NOT to support
  # class hierarchies with abstract base classes in Rails 2.x
  describe :find do
    it "returns all AR models" do
      keys = finder.find({}).keys
      if Rails::VERSION::MAJOR > 2
        keys.should == [AbstractParentClass, CarSeat, NotConventional, Part, StiParent]
      else
        keys.should == [CarSeat, Part, StiParent]
      end
    end

    it "returns all columns for each model" do
      attributes = finder.find({})
      attributes[CarSeat].should == ['id', 'seat_color']
      attributes[NotConventional].should == ['id', 'name'] if Rails::VERSION::MAJOR > 2
      attributes[Part].should == ['car_seat_id', 'id', 'name']
      attributes[StiParent].should == ['child_attribute', 'id', 'type']
      attributes[AbstractParentClass].should == 
        ['another_child_attribute', 'child_attribute', 'id'] if Rails::VERSION::MAJOR > 2
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gettext_i18n_rails-0.10.0 spec/gettext_i18n_rails/model_attributes_finder_spec.rb