Sha256: a8cec06f05525cc7d22a5124f80063bf596603f42711faffbc97fbfb0ee93e36

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require "spec_helper"
require 'fixtures/item'
require 'db/db_creator'

describe Rand::Orders do
  %w[sqlite postgresql mysql].each do |adapter|
    context adapter do
      before(:all) do
        @db_creator = DBCreator.new adapter
        @db_creator.establish_connection
      end

      before(:each) do
        Item.delete_all

        @items = []
        5.times { |i| @items << Item.make!(amount: i) }

        stub(Item).random { Item.all }
        stub(Item).random_in_range { Item.all[1..2] }
        stub(Item).random_equal { Item.all[1] }
        stub(Item).select_random { |field| Item.pluck(field) }
      end

      context "random method" do
        it "should return 5 records" do
          Item.random.size.should be_equal(5)
        end
      end

      context "random_in_range method" do
        it "should return 2 records" do
          Item.random_in_range(:amount, (2..3)).size.should be_equal(2)
        end
      end

      context "random_equal method" do
        it "should return item with amount equal 1" do
          Item.random_equal(:amount, 1).amount.should be_equal(1)
        end
      end

      context "select_random method" do
        it "should return only selected field" do
          Item.select_random(:amount).first.class.should be_equal(Fixnum)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rand-orders-0.0.3 spec/rand-orders/stubed_rand_orders_spec.rb