Sha256: 8ca82a73aee251765194da0e6f8bc2e3462fabf0fb66d693da051a59f66f54fe

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

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

describe "Dynamoid::Associations::HasAndBelongsToMany" do

  before do
    @subscription = Subscription.create
    @camel_case = CamelCase.create
  end
  
  it 'determines equality from its records' do
    @user = @subscription.users.create
    
    @subscription.users.size.should == 1
    @subscription.users.should include @user
  end

  it 'determines target association correctly' do
    @subscription.users.send(:target_association).should == :subscriptions
    @camel_case.subscriptions.send(:target_association).should == :camel_cases
  end
  
  it 'determines target attribute' do
    @subscription.users.send(:target_attribute).should == :subscriptions_ids
  end
  
  it 'associates has_and_belongs_to_many automatically' do
    @user = @subscription.users.create
    
    @user.subscriptions.size.should == 1
    @user.subscriptions.should include @subscription
    @subscription.users.size.should == 1
    @subscription.users.should include @user

    @user = User.create
    @follower = @user.followers.create
    @follower.following.should include @user
    @user.followers.should include @follower
  end
  
  it 'disassociates has_and_belongs_to_many automatically' do
    @user = @subscription.users.create
    
    @subscription.users.delete(@user)
    @subscription.users.size.should == 0
    @user.subscriptions.size.should == 0
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
dynamoid-moda-0.7.2 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-moda-0.7.1 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.7.1 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.7.0 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.6.1 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.6.0 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
adept_dynamoid-0.6.0 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
adept_dynamoid-0.5.0.8 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
adept_dynamoid-0.5.0.7 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
adept_dynamoid-0.5.0.6 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.5.0 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.4.1 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.4.0 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.3.2 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.3.1 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb
dynamoid-0.3.0 spec/dynamoid/associations/has_and_belongs_to_many_spec.rb