Sha256: 544c263af384068266faefb2adbf4d3fc3bbf16691d4329fa84ae67f382e4ae7

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'

class Superstore::FinderMethodsTest < Superstore::TestCase
  test 'find' do
    Issue.create.tap do |issue|
      assert_equal issue, Issue.find(issue.id)
    end

    begin
      Issue.find(nil)
      assert false
    rescue => e
      assert_equal "Couldn't find Issue with key nil", e.message
    end

    assert_raise Superstore::RecordNotFound do
      Issue.find('what')
    end
  end

  test 'find with ids' do
    first_issue = Issue.create
    second_issue = Issue.create
    third_issue = Issue.create

    assert_equal [], Issue.find([])
    assert_equal [first_issue, second_issue], Issue.find([first_issue.id, second_issue.id])
  end

  test 'find with nil ids' do
    Issue.create
    assert_equal [], Issue.find([nil])
  end

  test 'find_by_id' do
    Issue.create.tap do |issue|
      assert_equal issue, Issue.find_by_id(issue.id)
    end

    assert_nil Issue.find_by_id('what')
  end

  test 'all' do
    first_issue = Issue.create
    second_issue = Issue.create

    assert_equal [first_issue, second_issue].to_set, Issue.all.to_set
  end

  test 'first' do
    first_issue = Issue.create
    second_issue = Issue.create

    assert [first_issue, second_issue].include?(Issue.first)
  end

  test 'to_ids' do
    first_issue = Issue.create title: 'Sup!'

    assert_equal [first_issue.id], Issue.to_ids
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
superstore-2.3.0 test/unit/scope/finder_methods_test.rb
superstore-2.2.0 test/unit/scope/finder_methods_test.rb
superstore-2.1.3 test/unit/scope/finder_methods_test.rb
superstore-2.1.2 test/unit/scope/finder_methods_test.rb