Skip to content

Commit

Permalink
Add tests for times option of ActiveRecord::Base::utusemi
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Jul 16, 2014
1 parent d1475bf commit 357154e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/dummy/db/migrate/20140710120737_create_products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/utusemi/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 357154e

Please sign in to comment.