Skip to content

Instantly share code, notes, and snippets.

@kimh

kimh/test.rb Secret

Last active August 29, 2015 14:10
Show Gist options
  • Save kimh/48962ea40dc048565dd2 to your computer and use it in GitHub Desktop.
Save kimh/48962ea40dc048565dd2 to your computer and use it in GitHub Desktop.
Assigne false becomes always nil
require 'lotus/model'
require 'sequel'
require 'sqlite3'
require 'minitest/autorun'
require 'pp'
class Item
include Lotus::Entity
self.attributes = :sold
end
class ItemRepository
include Lotus::Repository
end
describe "taste field is not mapped" do
before(:each) do
uri = "sqlite:///tmp/test.db"
Lotus::Model.configure do
adapter type: :sql, uri: uri, default: true
mapping do
collection :items do
entity Item
attribute :id, Integer
attribute :sold, Boolean
end
end
end
database = Sequel.connect(uri)
database.drop_table? :items
database.create_table :items do
primary_key :id
Boolean :sold
end
Lotus::Model.load!
end
it 'setting sold field to false is nil' do
ItemRepository.create(Item.new(sold: false))
ItemRepository.first.sold.must_be_nil
end
it 'but setting to true works' do
ItemRepository.create(Item.new(sold: true))
ItemRepository.first.sold.must_equal true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment