Skip to content

Commit

Permalink
all tests passing for Rails 4.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
treble37 committed Dec 14, 2014
1 parent af32547 commit 1c86428
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.6)
arel (5.0.1.20140414130214)
builder (3.2.2)
capybara (2.4.4)
Expand Down Expand Up @@ -76,6 +77,8 @@ GEM
hitimes (1.2.2)
i18n (0.6.11)
json (1.8.1)
launchy (2.4.3)
addressable (~> 2.3)
listen (2.8.3)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
Expand Down Expand Up @@ -168,6 +171,7 @@ DEPENDENCIES
capybara
guard-rspec
guard-spork
launchy
obfuscate_id!
pry
rb-inotify
Expand Down
23 changes: 21 additions & 2 deletions lib/obfuscate_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def self.show(id, spin)


module ClassMethods
@@no_obfuscated_id = false
def find(*args)
scope = args.slice!(0)
options = args.slice!(0) || {}
Expand Down Expand Up @@ -60,9 +59,29 @@ def to_param

# As ActiveRecord::Persistence#reload uses self.id
# reload without deobfuscating
# def reload(options = nil)
# options = (options || {}).merge(:no_obfuscated_id => true)
# super(options)
# end

def reload(options = nil)
options = (options || {}).merge(:no_obfuscated_id => true)
super(options)
clear_aggregation_cache
clear_association_cache
fresh_object =
if options && options[:lock]
self.class.unscoped { self.class.lock(options[:lock]).find(id, options) }
else
self.class.unscoped { self.class.find(id, options) }
end

@attributes.update(fresh_object.instance_variable_get('@attributes'))

@column_types = self.class.column_types
@column_types_override = fresh_object.instance_variable_get('@column_types_override')
@attributes_cache = {}
@new_record = false
self
end

def deobfuscate_id(obfuscated_id)
Expand Down
1 change: 1 addition & 0 deletions obfuscate_id.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "guard-spork"
s.add_development_dependency "rb-inotify"
s.add_development_dependency "pry"
s.add_development_dependency "launchy"
end
2 changes: 0 additions & 2 deletions spec/dummy/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
8 changes: 7 additions & 1 deletion spec/dummy/app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class CommentsController < ApplicationController

def create
@comment = Comment.create! params[:comment]
@comment = Comment.create! comment_params
redirect_to post_path(@comment.post)
end

private

def comment_params
params.require(:comment).permit(:post_id, :content)
end
end
6 changes: 5 additions & 1 deletion spec/dummy/app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ def new
end

def create
@post = Post.create!(params[:post])
@post = Post.create!(post_params)
redirect_to @post
end

def show
@post = Post.find(params[:id])
end

def post_params
params.require(:post).permit(:id, :content)
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require File.expand_path("../dummy/config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand All @@ -35,6 +36,8 @@
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.include Capybara::DSL
config.include Rails.application.routes.url_helpers
end
end

Expand Down

0 comments on commit 1c86428

Please sign in to comment.