Sha256: 1d71a9c071701f13697a786ae571b94f37eb244e078f89fa9a457e75201c1f9c

Contents?: true

Size: 1.75 KB

Versions: 23

Compression:

Stored size: 1.75 KB

Contents

require 'rails_helper'

describe MagicLocales::Association do
  
  
  class TestPerson < ActiveRecord::Base
    self.table_name = "users"
  end

  class TestUser < ActiveRecord::Base
    self.table_name = "users"
    has_one_language
  end
  
  class TestDude < ActiveRecord::Base
    self.table_name = "users"
    has_languages
  end

  describe "has some kind of address => inherit methods" do

    let(:person){ TestPerson.create!( name: "Bud Spencer"   ) }
    let(:user){   TestUser.create!(   name: "Terence Hill"  ) }
    let(:dude){   TestDude.create!(   name: "The Dude"      ) }


    it "add address attributes only if asked for" do
      expect( person.respond_to?(:language) ).to be false
      expect( user.respond_to?(:language) ).to be true
      expect( dude.respond_to?(:language) ).to be false
      
      expect( person.respond_to?(:spoken_languages) ).to be false
      expect( user.respond_to?(:spoken_languages) ).to be false
      expect( dude.respond_to?(:spoken_languages) ).to be true
      
      expect( person.respond_to?(:foreign_languages) ).to be false
      expect( user.respond_to?(:foreign_languages) ).to be false
      expect( dude.respond_to?(:foreign_languages) ).to be true
      
      expect( person.respond_to?(:native_languages) ).to be false
      expect( user.respond_to?(:native_languages) ).to be false
      expect( dude.respond_to?(:native_languages) ).to be true
    end

  end
  
  describe "has_one_address => inherit methods" do

    let(:micha){ TestPerson.create!(name: "Micha Schmidt") }

    let(:ingo){ TestUser.create!(name: "Ingo Mueller") }

    it "add address attributes only if asked for" do
      expect( ingo.respond_to?(:language) ).to be true
      expect( micha.respond_to?(:language) ).to be false
    end

  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
magic_locales-0.0.21 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.20 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.19 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.18 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.17 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.17.beta2 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.17.beta1 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.16 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.15 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.14 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.13 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.12 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.11 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.10 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.9 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.8 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.7 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.6 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.5 spec/models/magic_locales/association_spec.rb
magic_locales-0.0.4 spec/models/magic_locales/association_spec.rb