Sha256: b5fd286df8b3a58e363011b40ffbfddaafef76947d088cfcb1bf0e10e95b0b85

Contents?: true

Size: 1.44 KB

Versions: 14

Compression:

Stored size: 1.44 KB

Contents

require 'gecko'

class Gecko::Helpers::AssociationHelperTest < Minitest::Test
  def setup
    @klass = Class.new(Gecko::Record::Base) do
      has_many :orders
      belongs_to :order
      belongs_to :small_order, class_name: "Order"
    end
    @client = Gecko::Client.new('ABC', 'DEF')
  end

  def test_adds_association_methods
    record = @klass.new(@client, {})
    assert(record.respond_to?(:orders))
    assert(record.respond_to?(:order))
    assert(record.respond_to?(:small_order))
  end

  def test_adds_id_methods
    record = @klass.new(@client, {})
    assert(record.respond_to?(:order_ids))
    assert(record.respond_to?(:order_id))
    assert(record.respond_to?(:small_order_id))
  end

  def test_has_many
    record = @klass.new(@client, {order_ids: [123]})
    @client.Order.expects(:find_many).with([123])
    record.orders
  end

  def test_has_many_without_ids
    record = @klass.new(@client, {order_ids: []})
    @client.Order.expects(:find_many).never
    assert_equal([], record.orders)
  end

  def test_belongs_to
    record = @klass.new(@client, {order_id: 4})
    @client.Order.expects(:find).with(4)
    record.order
  end

  def test_belongs_to_without_id
    record = @klass.new(@client, {order_id: nil})
    @client.Order.expects(:find).never
    assert_nil record.order
  end

  def test_belongs_to_with_class
    record = @klass.new(@client, {small_order_id: 56})
    @client.Order.expects(:find).with(56)
    record.small_order
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gecko-ruby-0.2.6 test/helpers/association_helper_test.rb
gecko-ruby-0.2.5 test/helpers/association_helper_test.rb
gecko-ruby-0.2.4 test/helpers/association_helper_test.rb
gecko-ruby-0.2.3 test/helpers/association_helper_test.rb
gecko-ruby-0.2.2 test/helpers/association_helper_test.rb
gecko-ruby-0.2.0 test/helpers/association_helper_test.rb
gecko-ruby-0.1.0 test/helpers/association_helper_test.rb
gecko-ruby-0.0.10 test/helpers/association_helper_test.rb
gecko-ruby-0.0.9 test/helpers/association_helper_test.rb
gecko-ruby-0.0.8 test/helpers/association_helper_test.rb
gecko-ruby-0.0.7 test/helpers/association_helper_test.rb
gecko-ruby-0.0.6 test/helpers/association_helper_test.rb
gecko-ruby-0.0.5 test/helpers/association_helper_test.rb
gecko-ruby-0.0.4 test/helpers/association_helper_test.rb