From 357154e816e91d6ce88fa292cb9cf7df273a2c4a Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Tue, 15 Jul 2014 18:22:26 +0900 Subject: [PATCH] Add tests for times option of ActiveRecord::Base::utusemi --- .../migrate/20140710120737_create_products.rb | 3 +++ spec/lib/utusemi/configuration_spec.rb | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/spec/dummy/db/migrate/20140710120737_create_products.rb b/spec/dummy/db/migrate/20140710120737_create_products.rb index 179d017..83c8c89 100644 --- a/spec/dummy/db/migrate/20140710120737_create_products.rb +++ b/spec/dummy/db/migrate/20140710120737_create_products.rb @@ -2,6 +2,9 @@ class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :title + t.string :description1 + t.string :description2 + t.string :description3 t.timestamps end end diff --git a/spec/lib/utusemi/configuration_spec.rb b/spec/lib/utusemi/configuration_spec.rb index 542662d..7cd35fb 100644 --- a/spec/lib/utusemi/configuration_spec.rb +++ b/spec/lib/utusemi/configuration_spec.rb @@ -1,2 +1,24 @@ describe Utusemi::Configuration do + describe '"times" option' do + let!(:product_one) { FactoryGirl.create(:product, description1: nil, description2: nil, description3: nil) } + let!(:product_two) { FactoryGirl.create(:product, description1: 'foo', description2: 'bar', description3: 'hoge') } + let!(:product_three) { FactoryGirl.create(:product, description1: 'foo', description2: 'bar', description3: nil) } + + before do + Utusemi.configure do + map(:sample) { |options| description "description#{options[:index]}" } + end + end + + subject { Product.utusemi(:sample, times: 3) } + + it 'found a record that all description are nil' do + expect(subject.where(description: nil).count).to eq(1) + end + + it 'found a record that all description are not nil' do + pending 'Rails 3 is not supported' if Rails::VERSION::MAJOR == 3 + expect(subject.where.not(description: nil).count).to eq(1) + end + end end