test/test_scheme.rb in swift-0.10.0 vs test/test_scheme.rb in swift-0.11.0
- old
+ new
@@ -9,10 +9,16 @@
attribute :age, Swift::Type::Integer, default: 18
attribute :height, Swift::Type::Float, default: 172.25
attribute :email, Swift::Type::String
attribute :verified, Swift::Type::Boolean, default: false
attribute :created_at, Swift::Type::Time, default: proc { Time.now }
+
+ migrations do |db|
+ db.execute %q{
+ create users(id serial, name text, age int, height real, email text, verified bool, created_at timestamp)
+ }
+ end
end
end
describe 'attributes' do
it 'defines attributes' do
@@ -60,47 +66,36 @@
it 'should return scheme instance when given scheme in #execute' do
user = @user.create
assert_equal 1, Swift.db.execute(@user, 'select * from users').first.id
end
- it 'adapter should destroy valid instance' do
+ it 'adapter should delete valid instance' do
user = @user.create
assert_equal 1, user.id
- assert Swift.db.destroy @user, user
+ assert Swift.db.delete @user, user
assert_nil @user.get(id: 1)
end
- it 'adapter should barf when trying to destroy invalid instance' do
- assert_raises(ArgumentError) { Swift.db.destroy @user, {id: nil, name: 'foo'} }
+ it 'adapter should barf when trying to delete an invalid instance' do
+ assert_raises(ArgumentError) { Swift.db.delete @user, {id: nil, name: 'foo'} }
end
- it 'adapter should delete all rows given scheme' do
- user = @user.create
- assert_equal 1, user.id
-
- Swift.db.delete @user
- assert_nil @user.get(id: 1)
- end
-
- it 'adapter should delete only relevant rows given condition & scheme' do
- Swift.db.create(@user, [{name: 'dave'}, {name: 'mike'}])
- assert_equal 2, @user.all.rows
-
- Swift.db.delete @user, ':name = ?', 'dave'
- assert_nil @user.first ':name = ?', 'dave'
- assert @user.first ':name = ?', 'mike'
- end
-
it 'should not update without valid keys' do
user = @user.new
assert_raises(ArgumentError) { user.update(name: 'dave') }
end
it 'should update with valid keys' do
user = @user.create
assert user.update(name: 'dave')
- assert_equal 'dave', @user.first.name
+ assert_equal 'dave', @user.execute("select * from #{@user}").first.name
+ end
+
+ it 'should destroy' do
+ user = @user.create
+ assert user.update(name: 'dave')
+ assert user.delete
end
end
end
end