Sha256: 607bbcae5c84571741fc517a9981a69218a4a6a8de16d40d1493399aa21cd90c

Contents?: true

Size: 1.32 KB

Versions: 11

Compression:

Stored size: 1.32 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe SimpleModelTranslations do
  context 'when generating nested attributes' do
    before do
      SomeModel = Class.new(ActiveRecord::Base)
    end
    
    after do
      Object.send(:remove_const, :SomeModel)
    end
    
    it 'can use options[:attributes] as a Hash' do
      options = { :reject_if => lambda { |attrs| attrs[:name].blank? } }
      SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, options.merge(:allow_destroy => true))
      SomeModel.translates :name, :attributes => options
    end
    
    it 'can use options[:attributes] as a Boolean' do
      SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, { :allow_destroy => true })
      SomeModel.translates :name, :attributes => true
    end
    
    it "should enable translations' deletion by default" do
      SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, { :allow_destroy => true })
      SomeModel.translates :name, :attributes => true
    end
    
    it "should allow to disable translations' deletion" do
      SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, { :allow_destroy => false })
      SomeModel.translates :name, :attributes => { :allow_destroy => false }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
simple_model_translations-0.2.8 spec/nested_attributes_spec.rb
simple_model_translations-0.2.7 spec/nested_attributes_spec.rb
simple_model_translations-0.2.6 spec/nested_attributes_spec.rb
simple_model_translations-0.2.5 spec/nested_attributes_spec.rb
simple_model_translations-0.2.4 spec/nested_attributes_spec.rb
simple_model_translations-0.2.3 spec/nested_attributes_spec.rb
simple_model_translations-0.2.2 spec/nested_attributes_spec.rb
simple_model_translations-0.2.1 spec/nested_attributes_spec.rb
simple_model_translations-0.2.0 spec/nested_attributes_spec.rb
simple_model_translations-0.1.9 spec/nested_attributes_spec.rb
simple_model_translations-0.1.8 spec/nested_attributes_spec.rb