diff --git a/Gemfile b/Gemfile index 5351f60..90c7c28 100644 --- a/Gemfile +++ b/Gemfile @@ -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" @@ -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 diff --git a/Rakefile b/Rakefile index 6d970ad..4c5d158 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ require "bundler/gem_tasks" require 'rake/testtask' require 'rdoc/task' +require 'neo4j/tasks/neo4j_server' task :default => [:test, :"neo4j:db:remove"] @@ -9,7 +10,7 @@ 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']) diff --git a/devise-neo4j.gemspec b/devise-neo4j.gemspec index 4d50b3e..ef565f7 100644 --- a/devise-neo4j.gemspec +++ b/devise-neo4j.gemspec @@ -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 \ No newline at end of file diff --git a/lib/devise/orm/neo4j.rb b/lib/devise/orm/neo4j.rb index d6070f7..624422d 100644 --- a/lib/devise/orm/neo4j.rb +++ b/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 \ No newline at end of file diff --git a/lib/devise/orm/neo4j/compatibility.rb b/lib/devise/orm/neo4j/compatibility.rb index ffc3a84..e7f47bd 100644 --- a/lib/devise/orm/neo4j/compatibility.rb +++ b/lib/devise/orm/neo4j/compatibility.rb @@ -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 diff --git a/lib/generators/neo4j/devise_generator.rb b/lib/generators/neo4j/devise_generator.rb index 096d8d1..114e696 100644 --- a/lib/generators/neo4j/devise_generator.rb +++ b/lib/generators/neo4j/devise_generator.rb @@ -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 @@ -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 diff --git a/test/generators/neo4j/devise_generator_test.rb b/test/generators/neo4j/devise_generator_test.rb index 770fb43..2d3ced4 100644 --- a/test/generators/neo4j/devise_generator_test.rb +++ b/test/generators/neo4j/devise_generator_test.rb @@ -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 diff --git a/test/orm/neo4j.rb b/test/orm/neo4j.rb index 575db8e..e540ee0 100755 --- a/test/orm/neo4j.rb +++ b/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 diff --git a/test/overrides/registerable_test.rb b/test/overrides/registerable_test.rb deleted file mode 100644 index 82b6f23..0000000 --- a/test/overrides/registerable_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test_helper' - -class RegistrationTest < ActionController::IntegrationTest - - undef :test_a_signed_in_user_should_not_change_his_current_user_with_invalid_password - undef :test_a_signed_in_user_should_not_be_able_to_edit_his_password_with_invalid_confirmation - - test 'a signed in user should not change his current user with invalid password' do - sign_in_as_user - get edit_user_registration_path - - fill_in 'email', :with => 'user.new@example.com' - fill_in 'current password', :with => 'invalid' - click_button 'Update' - - assert_template 'registrations/edit' - - assert_contain 'user@test.com' -# the email reverts to the original email and not the incorrect one. - assert_have_selector 'form input[value="user@test.com"]' - assert_contain "Current password is invalid" - assert_equal "user@test.com", User.first.email - end - - test 'a signed in user should not be able to edit his password with invalid confirmation' do - sign_in_as_user - get edit_user_registration_path - - fill_in 'password', :with => 'pas123' - fill_in 'password confirmation', :with => 'bullshit' - # in their original they borked the password. - fill_in 'current password', :with => '12345678' - click_button 'Update' - - assert_contain "Password doesn't match confirmation" - # Unsure why this test is not passing. Cannot replicate in a running app or using a unit test. - # Validation is run (hence the error message). Will investigate. - #assert_not User.first.valid_password?('pas123') - end - -end \ No newline at end of file diff --git a/test/rails_app/app/neo4j/admin.rb b/test/rails_app/app/neo4j/admin.rb index f0831e6..86a85a6 100755 --- a/test/rails_app/app/neo4j/admin.rb +++ b/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 @@ -14,10 +18,10 @@ 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 @@ -25,7 +29,7 @@ class Admin < Neo4j::Rails::Model ## Lockable property :locked_at, :type => DateTime - property :active, :type => :boolean, :default => false + property :active, :type => Boolean, :default => false def active? return self.active diff --git a/test/rails_app/app/neo4j/user.rb b/test/rails_app/app/neo4j/user.rb index b818d93..5817be1 100755 --- a/test/rails_app/app/neo4j/user.rb +++ b/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 \ No newline at end of file diff --git a/test/rails_app/config/application.rb b/test/rails_app/config/application.rb index a19daf2..368780a 100755 --- a/test/rails_app/config/application.rb +++ b/test/rails_app/config/application.rb @@ -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 @@ -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 diff --git a/test/support/fix_last.rb b/test/support/fix_last.rb deleted file mode 100755 index 08d3eb4..0000000 --- a/test/support/fix_last.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Neo4j::Rails::Model - - - # Hack to get around the fact that Neo4j doesn't support :order (currently) - def self.last(*args) - if args == [{ :order => "id" }] - last - else - super - end - end -end - - \ No newline at end of file diff --git a/test/test_models.rb b/test/test_models.rb new file mode 100644 index 0000000..ec3710f --- /dev/null +++ b/test/test_models.rb @@ -0,0 +1,33 @@ +class Configurable < User + devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable, + :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days, + :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days +end + +class WithValidation < Admin + devise :database_authenticatable, :validatable, :password_length => 2..6 +end + +class UserWithValidation < User + validates_presence_of :username +end + +class UserWithCustomEncryption < User + protected + def password_digest(password) + password.reverse + end +end + +class UserWithVirtualAttributes < User + devise :case_insensitive_keys => [ :email, :email_confirmation ] + validates :email, :presence => true, :confirmation => {:on => :create} +end + +class Several < Admin + devise :validatable + devise :lockable +end + +class Inheritable < Admin +end