Skip to content

Commit

Permalink
Merge pull request #33 from namick/rails-v4.2.0
Browse files Browse the repository at this point in the history
Support Rails 4.2.0
  • Loading branch information
namick committed Feb 8, 2015
2 parents 1eb490e + 127515f commit 488f91b
Show file tree
Hide file tree
Showing 122 changed files with 3,653 additions and 547 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.bundle/
log/*.log
pkg/
spec/dummy/db/*.sqlite3
spec/dummy/log/*.log
spec/dummy/tmp/
spec/dummy/.sass-cache
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: ruby
rvm:
- 1.9.3
before_script:
- cd spec/dummy && bundle exec rake db:test:load && cd -
- 2.1.1
105 changes: 60 additions & 45 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,49 @@ PATH
remote: .
specs:
obfuscate_id (0.0.4)
activeresource (~> 4.0.0)
rails (~> 4.1.8)
rails (~> 4.2.0)
scatter_swap (~> 0.0.3)

GEM
remote: http://rubygems.org/
specs:
actionmailer (4.1.8)
actionpack (= 4.1.8)
actionview (= 4.1.8)
actionmailer (4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
mail (~> 2.5, >= 2.5.4)
actionpack (4.1.8)
actionview (= 4.1.8)
activesupport (= 4.1.8)
rack (~> 1.5.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.0)
actionview (= 4.2.0)
activesupport (= 4.2.0)
rack (~> 1.6.0)
rack-test (~> 0.6.2)
actionview (4.1.8)
activesupport (= 4.1.8)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.8)
activesupport (= 4.1.8)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0)
activesupport (= 4.2.0)
globalid (>= 0.3.0)
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.1.8)
activemodel (= 4.1.8)
activesupport (= 4.1.8)
arel (~> 5.0.0)
activeresource (4.0.0)
activemodel (~> 4.0)
activesupport (~> 4.0)
rails-observers (~> 0.1.1)
activesupport (4.1.8)
i18n (~> 0.6, >= 0.6.9)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.6)
arel (5.0.1.20140414130214)
arel (6.0.0)
builder (3.2.2)
capybara (2.4.4)
mime-types (>= 1.16)
Expand All @@ -57,6 +61,8 @@ GEM
erubis (2.7.0)
ffi (1.9.6)
formatador (0.2.5)
globalid (0.3.2)
activesupport (>= 4.1.0)
guard (2.10.2)
formatador (>= 0.2.4)
listen (~> 2.7)
Expand All @@ -75,46 +81,55 @@ GEM
spork (>= 0.8.4)
hike (1.2.3)
hitimes (1.2.2)
i18n (0.6.11)
json (1.8.1)
i18n (0.7.0)
json (1.8.2)
launchy (2.4.3)
addressable (~> 2.3)
listen (2.8.3)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
loofah (2.0.1)
nokogiri (>= 1.5.9)
lumberjack (1.0.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.4.3)
mini_portile (0.6.1)
minitest (5.5.0)
minitest (5.5.1)
multi_json (1.10.1)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack-test (0.6.2)
rack (1.6.0)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.8)
actionmailer (= 4.1.8)
actionpack (= 4.1.8)
actionview (= 4.1.8)
activemodel (= 4.1.8)
activerecord (= 4.1.8)
activesupport (= 4.1.8)
rails (4.2.0)
actionmailer (= 4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
activemodel (= 4.2.0)
activerecord (= 4.2.0)
activesupport (= 4.2.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.8)
sprockets-rails (~> 2.0)
rails-observers (0.1.2)
activemodel (~> 4.0)
railties (4.1.8)
actionpack (= 4.1.8)
activesupport (= 4.1.8)
railties (= 4.2.0)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
loofah (~> 2.0)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
Expand Down Expand Up @@ -149,7 +164,7 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.2)
sprockets-rails (2.2.4)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ obfuscate_id turns a URL like this:
into something like:

http://example.com/users/2356513904

Sequential ActiveRecord ids become non-sequential, random looking, numeric ids.

# post 7000
Expand All @@ -22,7 +22,7 @@ Sequential ActiveRecord ids become non-sequential, random looking, numeric ids.
http://example.com/posts/7107163820
# post 7002
http://example.com/posts/3296163828

## Why would you want this?

If your site is scaling well, you might not want to leak that you are getting 50 new posts a minute.
Expand Down Expand Up @@ -52,7 +52,7 @@ Run bundler.

## Usage

In your model, add a single line.
In your model, add a single line.

class Post < ActiveRecord::Base
obfuscate_id
Expand Down Expand Up @@ -81,6 +81,12 @@ ActiveRecord reverses this obfuscated id back to the plain id before building th
* This is not security. obfuscate_id was created to lightly mask record id numbers for the casual user. If you need to really secure your database ids (hint, you probably don't), you need to use real encryption like AES.
* To properly generate obfuscated urls, make sure you trigger the model's `to_param` method by passing in the whole object rather than just the id; do this: `post_path(@post)` not this: `post_path(@post.id)`.

## Versions

This is tested with Rails 4.2.0. For other versions of Rails, please see [the releases](https://github.com/namick/obfuscate_id/releases).

If you are trying to get it to work with a different version of rails that is not tested, let me know in [the issues](https://github.com/namick/obfuscate_id/issues)

## Development

To run the tests, first clone the repo and run bundler:
Expand All @@ -89,12 +95,6 @@ To run the tests, first clone the repo and run bundler:
cd obfuscate_id
bundle install

Change to the dummy rails app and load the test database

cd spec/dummy
bundle exec rake db:test:load
cd -

Run the tests

bundle exec rspec spec
Expand Down
16 changes: 4 additions & 12 deletions lib/obfuscate_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,20 @@ 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)
options = (options || {}).merge(no_obfuscated_id: true)
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
@attributes = fresh_object.instance_variable_get('@attributes')
@new_record = false
self
end

Expand Down
3 changes: 1 addition & 2 deletions obfuscate_id.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]

s.add_dependency "scatter_swap", "~> 0.0.3"
s.add_dependency "rails", "~> 4.1.8"
s.add_dependency "activeresource", "~> 4.0.0"
s.add_dependency "rails", "~> 4.2.0"

s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails"
Expand Down
17 changes: 17 additions & 0 deletions spec/dummy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/development.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
45 changes: 45 additions & 0 deletions spec/dummy/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

Loading

0 comments on commit 488f91b

Please sign in to comment.