adding user repository unit tests

parent c4c63467
......@@ -23,18 +23,6 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_and_belongs_to_many :roles
after_create SyncUserRepositoryService.new
after_destroy SyncUserRepositoryService.new
def graph_id
@graph_id ||= user_repository.get_graph_id(self)
end
private
def user_repository
Portalmec::Application.repository.for :user
end
end
......@@ -3,7 +3,7 @@ module OrientDb
include OrientDb::Methods::EdgeMethods
def increment_views(user, learning_object)
create_edge "Views", user.graph_id, learning_object.id
create_edge "Views", user.rid, learning_object.id
end
#
......@@ -11,7 +11,7 @@ module OrientDb
# repository.for(:learning_objects).like @learning_object, current_user
#
def like(user, learning_object)
create_edge "Likes", user.graph_id, learning_object.id
create_edge "Likes", user.rid, learning_object.id
end
# Example:
......
development: &development
host: localhost
database: PortalMEC_v2
database: portalmec
username: admin
password: admin
port: 2480
......
class AddRidColumnToUsers < ActiveRecord::Migration
def change
add_column :users, :rid, :string
end
end
require 'test_helper'
class OrientDb::UserRepositoryTest < ActiveSupport::TestCase
end
\ No newline at end of file
require 'test_helper'
class UserRepositoryProxyTest < ActiveSupport::TestCase
#def create_graph_node(user)
# orientdb_user_repository.create_graph_node user
# ensure_user_consistency user
#end
test 'raise an exception when create graph node with not persisted user' do
user = User.new
odb_user_repository = mock
odb_user_repository.expect(:create_graph_node, nil, [user])
repository = UserRepositoryProxy.new odb_user_repository
assert_raise ::NotPersistedRecordError do
repository.create_graph_node user
end
end
test 'ensure a persisted user is linked in both storages' do
odb_user_repository = mock
repository = UserRepositoryProxy.new odb_user_repository
repository.ensure_user_consistency user
end
end
\ No newline at end of file
......@@ -2,6 +2,8 @@ ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'shoulda-callback-matchers'
require 'minitest/mock'
require 'repository/not_persisted_record_error'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
......@@ -13,4 +15,8 @@ class ActiveSupport::TestCase
assert_equal expected.to_i, actual.count
end
def mock
MiniTest::Mock.new
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment