test/upgrow/basic_repository_test.rb in upgrow-0.0.3 vs test/upgrow/basic_repository_test.rb in upgrow-0.0.4
- old
+ new
@@ -2,29 +2,19 @@
require 'test_helper'
module Upgrow
class BasicRepositoryTest < ActiveSupport::TestCase
- class User < BasicModel; end
-
- class Car < BasicModel
- attribute :wheels
- end
-
class UserRepository < BasicRepository; end
- class NoModelRepository < BasicRepository; end
-
setup do
@original_base = UserRepository.base
- @original_model_class = UserRepository.model_class
@repository = UserRepository.new
end
teardown do
UserRepository.base = @original_base
- UserRepository.model_class = @original_model_class
end
test '.base is nil by default' do
assert_nil UserRepository.base
end
@@ -32,63 +22,11 @@
test '.base can be set' do
UserRepository.base = :my_base
assert_equal :my_base, UserRepository.base
end
- test '.model_class is iferred based on the Repository name' do
- assert_equal User, UserRepository.model_class
- end
-
- test '.model_class can be set' do
- UserRepository.model_class = :my_model_class
- assert_equal :my_model_class, UserRepository.model_class
- end
-
- test '.model_class raises a Name Error if the Model class is undefined' do
- error = assert_raises(NameError) do
- NoModelRepository.model_class
- end
-
- assert_includes(
- error.message,
- 'uninitialized constant Upgrow::BasicRepositoryTest::NoModel'
- )
- end
-
test '#base is inferred from the Repository class base' do
UserRepository.base = :my_base
assert_equal :my_base, UserRepository.new.base
- end
-
- test '#model_class is inferred from the Repository class Model class' do
- UserRepository.model_class = :my_model_class
- assert_equal :my_model_class, UserRepository.new.model_class
- end
-
- test '#to_model returns a new Model with the given attributes as keyword arguments' do
- model = @repository.to_model(id: 1)
-
- assert_equal 1, model.id
- end
-
- test '#to_model accepts a Model class explicitly' do
- model = @repository.to_model(Car, id: 1, wheels: 4)
-
- assert_equal 1, model.id
- assert_equal 4, model.wheels
- end
-
- test '#to_model accepts a Hash of Symbols' do
- args = { id: 1 }
- model = @repository.to_model(args)
-
- assert_equal 1, model.id
- end
-
- test '#to_model accepts a Hash of Strings' do
- args = { 'id' => 1 }
- model = @repository.to_model(args)
-
- assert_equal 1, model.id
end
end
end