Skip to content

Commit

Permalink
Updated for Rails 4
Browse files Browse the repository at this point in the history
Modules prepend, using Ruby 2.0ish way of prepending features
  • Loading branch information
bcardarella committed Jun 10, 2013
1 parent ed4917e commit 7473af4
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 73 deletions.
10 changes: 1 addition & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
source "http://rubygems.org"

# Only install appropriate ruby debugger if we are not on travis
unless ENV['CI']
if RUBY_VERSION >= '1.9.2' && RUBY_ENGINE == 'ruby'
gem 'debugger'
end
if RUBY_VERSION == '1.8.7'
gem 'ruby-debug'
end
end
gemspec
gem "jquery-rails"
gem 'byebug'
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'bundler/setup'
require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
require 'byebug'

RSpec::Core::RakeTask.new('default') do |t|
t.pattern = FileList['spec/**/*_spec.rb']
end

APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks
4 changes: 2 additions & 2 deletions easy_auth-password.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Gem::Specification.new do |s|

s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec-rails', '~> 2.11.4'
s.add_development_dependency 'capybara', '~> 1'
s.add_development_dependency 'capybara-email', '~> 1'
s.add_development_dependency 'capybara', '~> 2.1'
s.add_development_dependency 'capybara-email', '~> 2.1.2'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'valid_attribute'
s.add_development_dependency 'factory_girl_rails', '~> 1.7.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/easy_auth/controllers/password_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def update
private

def account_params
params[ActiveModel::Naming.param_key(@account)]
params.require(ActiveModel::Naming.param_key(@account)).permit(:password, :password_confirmation)
end

def find_account_from_reset_token
Expand Down
2 changes: 1 addition & 1 deletion lib/easy_auth/models/identities/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module EasyAuth::Models::Identities::Password
include EasyAuth::TokenGenerator
extend ActiveSupport::Concern

prepended do
included do
# Attributes
attr_reader :password
alias_attribute :password_digest, :token
Expand Down
1 change: 1 addition & 0 deletions lib/easy_auth/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Models
module Account
prepend EasyAuth::Password::Models::Account
end

module Identity
prepend EasyAuth::Password::Models::Identity
end
Expand Down
8 changes: 1 addition & 7 deletions lib/easy_auth/password/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class NoIdentityUIDError < StandardError; end

prepended do
# Attributes
attr_accessor :password_reset, :password
attr_accessor :password, :password_reset

# Validations
validates :password, :presence => { :if => :password_reset }, :confirmation => true
Expand All @@ -13,7 +13,6 @@ class NoIdentityUIDError < StandardError; end
end

# Callbacks
#before_update :update_password_identities, :if => :run_password_identity_validations?
before_save :update_password_identities, :if => :can_update_password_identities?

# Associations
Expand Down Expand Up @@ -47,11 +46,6 @@ def run_password_identity_validations?
self.password.present? || self.password_identities.present?
end

#def password=(password)
#@password = password
#update_password_identities
#end

private

def can_update_password_identities?
Expand Down
6 changes: 5 additions & 1 deletion lib/easy_auth/password/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def easy_auth_password_routes
post '/password_reset' => 'password_reset#create', :defaults => { :identity => 'password' }

get '/password_reset/:id/:reset_token' => 'password_reset#edit', :defaults => { :identity => 'password' }, :as => :edit_password_reset
put '/password_reset/:id/:reset_token' => 'password_reset#update', :defaults => { :identity => 'password' }
if Rails.version >= '4.0.0'
patch '/password_reset/:id/:reset_token' => 'password_reset#update', :defaults => { :identity => 'password' }
else
put '/password_reset/:id/:reset_token' => 'password_reset#update', :defaults => { :identity => 'password' }
end
end
end
17 changes: 10 additions & 7 deletions spec/config/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
require 'database_cleaner'

RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean
DatabaseCleaner.strategy = :deletion
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
DatabaseCleaner.start
DatabaseCleaner.strategy = :transaction
end

config.after(:each) do
DatabaseCleaner.clean
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end

at_exit do
config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end
end
1 change: 0 additions & 1 deletion spec/dummy/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class User < ActiveRecord::Base
$T = true
include EasyAuth::Models::Account
end
8 changes: 0 additions & 8 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'active_resource/railtie'
require 'sprockets/railtie'

Bundler.require
Expand Down Expand Up @@ -45,17 +44,10 @@ class Application < Rails::Application
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql

# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = false

# Enable the asset pipeline
config.assets.enabled = true

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end

11 changes: 1 addition & 10 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Expand All @@ -22,18 +19,12 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5

# Do not compress assets
config.assets.compress = false

# Expands the lines which load the assets
config.assets.debug = true

config.action_mailer.default_url_options = { :host => 'easy_auth.local' }
config.eager_load = false
end
7 changes: 1 addition & 6 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Log error messages when you accidentally call methods on nil
config.whiny_nils = true

# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Expand All @@ -29,11 +26,9 @@
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict

# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr

config.action_mailer.default_url_options = { :host => 'example.com' }
config.eager_load = false
end
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/secret_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Dummy::Application.config.secret_token = '88f16662bce41e31ee0b55982ef06db802f1b5f07dac75e0c5c5856c5d6f93a0002985bab0e3a885eae5c3dcbec5c237085004dab2ead1b47a74762ca4f09e98'
Dummy::Application.config.secret_key_base = '88f16662bce41e31ee0b55982ef06db802f1b5f07dac75e0c5c5856c5d6f93a0002985bab0e3a885eae5c3dcbec5c237085004dab2ead1b47a74762ca4f09e98'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This migration comes from easy_auth_password (originally 20120227014024)
class CreateEasyAuthPassword < ActiveRecord::Migration
def change
add_column :identities, :remember_token_digest, :string
add_column :identities, :reset_token_digest, :string
end
end
18 changes: 9 additions & 9 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120227014024) do
ActiveRecord::Schema.define(version: 20130610064414) do

create_table "identities", :force => true do |t|
create_table "identities", force: true do |t|
t.string "uid"
t.string "token"
t.string "account_type"
t.integer "account_id"
t.string "type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "remember_token_digest"
t.string "reset_token_digest"
end

add_index "identities", ["uid"], :name => "index_identities_on_uid"
add_index "identities", ["uid"], name: "index_identities_on_uid"

create_table "users", :force => true do |t|
create_table "users", force: true do |t|
t.string "email"
t.string "username"
t.string "session_token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

end
23 changes: 13 additions & 10 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'rubygems'
begin
require 'debugger'
rescue LoadError
end
begin
require 'ruby-debug'
rescue LoadError
end
# begin
# require 'debugger'
# rescue LoadError
# end
# begin
# require 'ruby-debug'
# rescue LoadError
# end
require 'bundler/setup'

require 'byebug'
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'capybara/rspec'
Expand All @@ -24,11 +24,14 @@

RSpec.configure do |config|
config.mock_with :mocha
config.use_transactional_fixtures = true
config.use_transactional_fixtures = false
config.include Factory::Syntax::Methods

config.before(:each, :type => :request) do
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/requests/step_helpers/**/*.rb')].each { |f| require f }
end
end

module Kernel
alias debugger byebug
end

0 comments on commit 7473af4

Please sign in to comment.