Skip to content

Commit

Permalink
Update to Neo4j 3 / Rails 4 / Devise 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ni-ka authored and andreasronge committed Jul 8, 2014
1 parent be07cfa commit 4f0a453
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 138 deletions.
10 changes: 5 additions & 5 deletions Gemfile
Expand Up @@ -2,12 +2,12 @@ source "http://rubygems.org"

gemspec

gem "rails"
gem "rails", "~> 4.0"
gem "omniauth"
gem "omniauth-oauth2"
gem "rdoc"
gem 'neo4j'
gem "devise", ">= 2.2.0"
gem 'neo4j', :git => 'https://github.com/andreasronge/neo4j.git'
gem "devise", "~> 3.0"
group :test do
gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1"
Expand All @@ -29,8 +29,8 @@ platforms :ruby do
gem "sqlite3"

group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "mongo"
gem "mongoid"
gem "bson_ext", "~> 1.3.0"
end
end
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -2,14 +2,15 @@
require "bundler/gem_tasks"
require 'rake/testtask'
require 'rdoc/task'
require 'neo4j/tasks/neo4j_server'


task :default => [:test, :"neo4j:db:remove"]

ENV['DEVISE_ORM'] = 'neo4j'
devise_checked_out = File.join(File.dirname(__FILE__), '../devise')
ENV['DEVISE_PATH'] = File.exist?(devise_checked_out) ? devise_checked_out : `bundle show devise`.chomp

puts ENV['DEVISE_PATH']
desc 'Run tests for devise-neo4j.'
Rake::TestTask.new(:test) do |test|
unless File.exist?(ENV['DEVISE_PATH'])
Expand Down
6 changes: 3 additions & 3 deletions devise-neo4j.gemspec
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_dependency("warden", "~> 1.2.1")
s.add_dependency("orm_adapter", "~> 0.1")
s.add_dependency("bcrypt-ruby", "~> 3.0")
s.add_dependency("railties", "~> 3.1")
s.add_dependency("railties", ">= 3.1")
s.add_dependency("neo4j", ">= 2.2.0")
s.add_dependency("devise", "~> 2.2.0")
end
s.add_dependency("devise", "~> 3.0")
end
20 changes: 5 additions & 15 deletions lib/devise/orm/neo4j.rb
@@ -1,22 +1,12 @@
require 'devise-neo4j'
require 'orm_adapter/adapters/neo4j'
require 'devise/orm/neo4j/date_time'
require 'devise/orm/neo4j/compatibility'
require 'devise/orm/neo4j/nil_class_converter'

module Neo4j
module Rails
class Model
include ActiveModel::Validations
extend ::Devise::Models
extend ::Devise::Orm::Neo4j::Hook
end
module ActiveNode
include ActiveModel::Validations
extend ::Devise::Models
extend ::Devise::Orm::Neo4j::Hook
end
end


converters = [ Neo4j::TypeConverters::NilClassConverter ]
Neo4j::TypeConverters.constants.find_all do |c|
converters << Neo4j::TypeConverters.const_get(c) if Neo4j::TypeConverters.const_get(c).respond_to?(:convert?)
end
Neo4j::TypeConverters.converters = converters.uniq
end
6 changes: 3 additions & 3 deletions lib/devise/orm/neo4j/compatibility.rb
Expand Up @@ -8,9 +8,9 @@ module Compatibility
extend ActiveSupport::Concern
included do

def assign_attributes(new_attributes)
attributes = sanitize_for_mass_assignment(new_attributes)
end
# def assign_attributes(new_attributes)
# attributes = sanitize_for_mass_assignment(new_attributes)
# end

end

Expand Down
12 changes: 6 additions & 6 deletions lib/generators/neo4j/devise_generator.rb
Expand Up @@ -34,8 +34,8 @@ def migration_data
property :username, :type => String
property :facebook_token, :type => String, :index => :exact
property :created_at, :type => Time
property :updated_at, :type => Time
property :created_at, :type => DateTime
property :updated_at, :type => DateTime
## Database authenticatable
property :email, :type => String, :null => false, :default => "", :index => :exact
Expand All @@ -44,18 +44,18 @@ def migration_data
## If you include devise modules, uncomment the properties below.
## Rememberable
property :remember_created_at, :type => Time
property :remember_created_at, :type => DateTime
index :remember_token, :type => :exact
## Recoverable
property :reset_password_token, :type => NilClass, :index => :exact
property :reset_password_sent_at, :type => Time
property :reset_password_sent_at, :type => DateTime
## Trackable
property :sign_in_count, :type => Fixnum, :default => 0
property :current_sign_in_at, :type => Time
property :last_sign_in_at, :type => Time
property :current_sign_in_at, :type => DateTime
property :last_sign_in_at, :type => DateTime
property :current_sign_in_ip, :type => String
property :last_sign_in_ip, :type => String
Expand Down
1 change: 0 additions & 1 deletion test/generators/neo4j/devise_generator_test.rb
Expand Up @@ -19,7 +19,6 @@ def assert_class(klass, content)
assert_file "app/models/player.rb" do |player|
assert_class "Player", player do |klass|
assert_match /Neo4j::Rails::Model/, klass
assert_match /attr_accessible :email, :password, :password_confirmation, :remember_me/, klass
end
end
end
Expand Down
48 changes: 36 additions & 12 deletions test/orm/neo4j.rb
@@ -1,18 +1,42 @@
require 'fileutils'

Neo4j.shutdown
FileUtils.rm_rf Neo4j::Config[:storage_path]
Neo4j.start
# mostly copied from neo4j/spec/spec_helper

EMBEDDED_DB_PATH = File.join(Dir.tmpdir, "neo4j-core-java")

I18n.enforce_available_locales = false

def create_session
if RUBY_PLATFORM != 'java'
create_server_session
else
require "neo4j-embedded/embedded_impermanent_session"
create_embedded_session
end
end

def create_embedded_session
session = Neo4j::Session.open(:impermanent_db, EMBEDDED_DB_PATH, auto_commit: true)
session.start
end

def create_server_session
Neo4j::Session.open(:server_db, "http://localhost:7474")
delete_db
end

FileUtils.rm_rf(EMBEDDED_DB_PATH)

Dir["#{File.dirname(__FILE__)}/shared_examples/**/*.rb"].each { |f| require f }

def delete_db
Neo4j::Session.current._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
end

class ActiveSupport::TestCase
teardown do
Neo4j.started_db.graph.getAllNodes.each do |n|
Neo4j::Transaction.run do
unless n.id == 0
n.rels.each { |r| r.delete unless r.nil? }
n.delete unless n.nil?
end
end
end
setup do
Neo4j::Session.current.close if Neo4j::Session.current
create_session
curr_session = Neo4j::Session.current
end
end
41 changes: 0 additions & 41 deletions test/overrides/registerable_test.rb

This file was deleted.

16 changes: 10 additions & 6 deletions test/rails_app/app/neo4j/admin.rb
@@ -1,8 +1,12 @@
require 'shared_admin'

class Admin < Neo4j::Rails::Model

index :email, :type => :exact # this need to come before any validations
class Admin
include Neo4j::ActiveNode
include ActiveModel::Validations
extend ::Devise::Models
extend ::Devise::Orm::Neo4j::Hook

index :email

property :created_at, :type => DateTime
property :updated_at, :type => DateTime
Expand All @@ -14,18 +18,18 @@ class Admin < Neo4j::Rails::Model

## Recoverable
property :reset_password_token, :type => String
property :reset_password_sent_at, :type => Time
property :reset_password_sent_at, :type => DateTime

## Confirmable
property :confirmation_token, :type => NilClass, :null => true, :index => :exact
property :confirmation_token, :type => String, :null => true, :index => :exact
property :confirmed_at, :type => DateTime
property :confirmation_sent_at, :type => DateTime
property :unconfirmed_email, :type => String

## Lockable
property :locked_at, :type => DateTime

property :active, :type => :boolean, :default => false
property :active, :type => Boolean, :default => false

def active?
return self.active
Expand Down
49 changes: 24 additions & 25 deletions test/rails_app/app/neo4j/user.rb
@@ -1,51 +1,50 @@
require 'shared_user'

class User < Neo4j::Rails::Model

class User
include Neo4j::ActiveNode
include ActiveModel::Validations
extend ::Devise::Models
extend ::Devise::Orm::Neo4j::Hook

property :username, :type => String
property :facebook_token, :type => String, :index => :exact
property :id

property :created_at, :type => Time
property :updated_at, :type => Time
property :created_at, :type => DateTime
property :updated_at, :type => DateTime

## Database authenticatable
property :email, :type => String, :null => false, :default => "", :index => :exact
property :encrypted_password, :type => NilClass
property :encrypted_password, :type => String

## Rememberable
property :remember_created_at, :type => Time
property :remember_created_at, :type => DateTime

## Recoverable
property :reset_password_token, :type => NilClass, :index => :exact
property :reset_password_sent_at, :type => Time
property :reset_password_token, :type => String, :index => :exact
property :reset_password_sent_at, :type => DateTime
## Trackable
property :sign_in_count, :type => Fixnum, :default => 0
property :current_sign_in_at, :type => Time
property :last_sign_in_at, :type => Time
property :current_sign_in_ip, :type => String
property :last_sign_in_ip, :type => String
property :sign_in_count, :type => Integer, :default => 0
property :current_sign_in_at, :type => DateTime
property :last_sign_in_at, :type => DateTime
property :current_sign_in_ip, :type => String
property :last_sign_in_ip, :type => String

## Confirmable
property :confirmation_token, :type => NilClass, :index => :exact
property :confirmation_token, :type => String, :index => :exact
property :confirmed_at, :type => DateTime
property :confirmation_sent_at, :type => DateTime

## Lockable
property :failed_attempts, :type => Fixnum, :default => 0
property :locked_at, :type => DateTime
property :unlock_token, :type => String, :index => :exact
property :failed_attempts, :type => Integer, :default => 0
property :locked_at, :type => DateTime
property :unlock_token, :type => String, :index => :exact

## Token authenticatable
property :authentication_token, :type => String, :null => true, :index => :exact
## Token authenticatable
property :authentication_token, :type => String, :null => true, :index => :exact


include Shim
include SharedUser
include Shim
include SharedUser

end

class UserWithValidation < User
validates_presence_of :username
end
11 changes: 5 additions & 6 deletions test/rails_app/config/application.rb
Expand Up @@ -3,7 +3,6 @@

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

Bundler.require :default, DEVISE_ORM
Expand All @@ -30,10 +29,10 @@ class Application < Rails::Application

config.action_mailer.default_url_options = { :host => "localhost:3000" }

#neo4j defaults
config.paths["log"] = File.join(Dir.tmpdir, 'devise-neo4j-tests', 'rails_app', 'log', 'test.log')
config.neo4j.storage_path = File.join(File.dirname(__FILE__), '..', "..", "..", "db")


if RUBY_PLATFORM == 'java'
#neo4j defaults
config.paths["log"] = File.join(Dir.tmpdir, 'devise-neo4j-tests', 'rails_app', 'log', 'test.log')
config.neo4j.storage_path = File.join(File.dirname(__FILE__), '..', "..", "..", "db")
end
end
end
14 changes: 0 additions & 14 deletions test/support/fix_last.rb

This file was deleted.

0 comments on commit 4f0a453

Please sign in to comment.