rails_temporary_data 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +80 -0
- data/Rakefile +13 -0
- data/app/models/temporary_data.rb +21 -0
- data/lib/generators/rails_temporary_data_generator.rb +23 -0
- data/lib/generators/templates/migration.rb +10 -0
- data/lib/rails_temporary_data.rb +7 -0
- data/lib/rails_temporary_data/controller_helpers.rb +23 -0
- data/lib/rails_temporary_data/engine.rb +9 -0
- data/lib/rails_temporary_data/version.rb +3 -0
- data/lib/tasks/rails_temporary_data.rake +8 -0
- data/rails_temporary_data.gemspec +26 -0
- data/test/controller_helpers_test.rb +43 -0
- data/test/dummy_rails_app/Rakefile +9 -0
- data/test/dummy_rails_app/app/controllers/application_controller.rb +3 -0
- data/test/dummy_rails_app/app/controllers/dummy_controller.rb +18 -0
- data/test/dummy_rails_app/app/helpers/application_helper.rb +2 -0
- data/test/dummy_rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/dummy_rails_app/config.ru +4 -0
- data/test/dummy_rails_app/config/application.rb +44 -0
- data/test/dummy_rails_app/config/boot.rb +10 -0
- data/test/dummy_rails_app/config/database.yml +20 -0
- data/test/dummy_rails_app/config/environment.rb +5 -0
- data/test/dummy_rails_app/config/environments/development.rb +26 -0
- data/test/dummy_rails_app/config/environments/production.rb +49 -0
- data/test/dummy_rails_app/config/environments/test.rb +35 -0
- data/test/dummy_rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy_rails_app/config/initializers/inflections.rb +10 -0
- data/test/dummy_rails_app/config/initializers/mime_types.rb +5 -0
- data/test/dummy_rails_app/config/initializers/secret_token.rb +7 -0
- data/test/dummy_rails_app/config/initializers/session_store.rb +8 -0
- data/test/dummy_rails_app/config/locales/en.yml +5 -0
- data/test/dummy_rails_app/config/routes.rb +58 -0
- data/test/dummy_rails_app/db/migrate/20120309215634_create_temporary_data.rb +10 -0
- data/test/dummy_rails_app/db/test.sqlite3 +0 -0
- data/test/dummy_rails_app/public/404.html +26 -0
- data/test/dummy_rails_app/public/422.html +26 -0
- data/test/dummy_rails_app/public/500.html +26 -0
- data/test/dummy_rails_app/public/favicon.ico +0 -0
- data/test/dummy_rails_app/public/stylesheets/.gitkeep +0 -0
- data/test/temporary_data_test.rb +68 -0
- data/test/test_helper.rb +17 -0
- metadata +179 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
RailsTemporaryData
|
2
|
+
==================
|
3
|
+
|
4
|
+
Rails engine to simply save big temporary data (too big for session cookie store) in a database. It is great for a step-by-step wizard or similar functionality.
|
5
|
+
|
6
|
+
Why
|
7
|
+
---
|
8
|
+
While working on [Padbase](http://www.padbase.com) we needed [2 steps signup process](http://www.padbase.com/pads/new) (1. enter property info, 2. enter user info). Info entered in first step could get very large and we couldn't save it in a session because of [CookieOverflow](http://api.rubyonrails.org/classes/ActionDispatch/Cookies/CookieOverflow.html), didn't want to switch to ActiveRecord store and didn't want to save invalid property in database with the flag (partial validations, ...). Solution was to create separate table for this temporary data and RailsTemporaryData was born.
|
9
|
+
**This way you get best from both worlds. Standard session data is still saved in a cookie and you can save larger amount of data in a database.**
|
10
|
+
|
11
|
+
Install
|
12
|
+
-------
|
13
|
+
|
14
|
+
Start by adding the gem to your application's Gemfile
|
15
|
+
|
16
|
+
gem 'rails_temporary_data', :git => 'git://github.com/vlado/rails_temporary_data.git'
|
17
|
+
|
18
|
+
Update your bundle
|
19
|
+
|
20
|
+
bundle install
|
21
|
+
|
22
|
+
Generate migration
|
23
|
+
|
24
|
+
rails generate rails_temporary_data
|
25
|
+
|
26
|
+
Run migration
|
27
|
+
|
28
|
+
rake db:migrate
|
29
|
+
|
30
|
+
Example
|
31
|
+
--------
|
32
|
+
|
33
|
+
class DummyController < ApplicationController
|
34
|
+
|
35
|
+
def set_data
|
36
|
+
set_tmp_data("some_key", { first_name: "Vlado", last_name: "Cingel", bio: "Very ... very long bio" })
|
37
|
+
...
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_data
|
41
|
+
tmp_data = get_tmp_data("some_key").data
|
42
|
+
# do something with tmp data
|
43
|
+
first_name = tmp_data[:first_name] # => Vlado
|
44
|
+
...
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
You can optionally set data expiry time (default is 2 days)
|
50
|
+
|
51
|
+
class DummyController < ApplicationController
|
52
|
+
|
53
|
+
def set_data
|
54
|
+
set_tmp_data("some_key", { first_name: "Vlado", last_name: "Cingel", bio: "Very ... very long bio" }, Time.now + 3.days)
|
55
|
+
...
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
To clear data you don't need any more
|
61
|
+
|
62
|
+
class DummyController < ApplicationController
|
63
|
+
|
64
|
+
def get_data
|
65
|
+
tmp_data = get_tmp_data("some_key").data
|
66
|
+
# do something with tmp data
|
67
|
+
clear_tmp_data("some_key")
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
To help you clear unwanted and/or expired data rake task is provided. You should set a cron job to call this task daily.
|
73
|
+
|
74
|
+
rake rails_temporary_data:delete_expired
|
75
|
+
|
76
|
+
|
77
|
+
TODO
|
78
|
+
----
|
79
|
+
|
80
|
+
* Default expires_at as configuration option
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class TemporaryData < ActiveRecord::Base
|
2
|
+
serialize :data
|
3
|
+
before_create :set_default_expires_at
|
4
|
+
|
5
|
+
scope :unexpired, lambda { where("expires_at > ?", Time.current) }
|
6
|
+
scope :expired, lambda { where("expires_at < ?", Time.current) }
|
7
|
+
|
8
|
+
def self.delete_expired
|
9
|
+
expired.delete_all
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.not_expired
|
13
|
+
unexpired
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_default_expires_at
|
19
|
+
self.expires_at = Time.current + 48.hours if expires_at.nil? || expires_at < Time.current
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class RailsTemporaryDataGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
14
|
+
else
|
15
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_migration_file
|
20
|
+
migration_template 'migration.rb', 'db/migrate/create_temporary_data.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RailsTemporaryData
|
2
|
+
module ControllerHelpers
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def set_tmp_data(key, data, expires_at = nil)
|
6
|
+
tmp_data = TemporaryData.create!(:data => data, :expires_at => expires_at)
|
7
|
+
session[key] = tmp_data.id
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_tmp_data(key)
|
11
|
+
tmp_data = TemporaryData.unexpired.find_by_id(session[key])
|
12
|
+
session[key] = nil if tmp_data.nil?
|
13
|
+
tmp_data
|
14
|
+
end
|
15
|
+
|
16
|
+
def clear_tmp_data(key)
|
17
|
+
tmp_data = TemporaryData.unexpired.find_by_id(session[key])
|
18
|
+
session[key] = nil
|
19
|
+
tmp_data.destroy if tmp_data
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rails_temporary_data/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rails_temporary_data"
|
7
|
+
s.version = RailsTemporaryData::VERSION
|
8
|
+
s.authors = ["Vlado Cingel"]
|
9
|
+
s.email = ["vladocingel@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Rails engine to simply save temporary data that is too big for session in database}
|
12
|
+
s.description = %q{Rails engine to simply save temporary data that is too big for session in database}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rails_temporary_data"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency("rake")
|
23
|
+
s.add_development_dependency("sqlite3")
|
24
|
+
|
25
|
+
s.add_dependency("rails")
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ControllerHelpersTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@controller = DummyController.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test "set and get tmp data" do
|
10
|
+
data = { "foo" => "bar" }
|
11
|
+
expires_at = Time.current + 24.hours
|
12
|
+
|
13
|
+
get :set_data, :data => data, :expires_at => expires_at
|
14
|
+
get :get_data
|
15
|
+
|
16
|
+
@tmp_data = assigns(:tmp_data)
|
17
|
+
|
18
|
+
assert_equal 1, session["test_data"]
|
19
|
+
assert_equal data, @tmp_data.data
|
20
|
+
assert_equal expires_at.to_a, @tmp_data.expires_at.to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
test "@tmp_data should not be returned (=nil) and session cleared if it is expired in the meantime" do
|
24
|
+
data = { "foo" => "bar" }
|
25
|
+
expires_at = Time.current + 1.second
|
26
|
+
|
27
|
+
get :set_data, :data => { "foo" => "bar" }, :expires_at => expires_at
|
28
|
+
sleep 1
|
29
|
+
get :get_data
|
30
|
+
|
31
|
+
assert_nil session["test_data"]
|
32
|
+
assert_nil assigns(:tmp_data)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "#clear_tmp_data shoould destroy both tmp data and sessions value" do
|
36
|
+
get :set_data, :data => { "foo" => "bar" }
|
37
|
+
assert_equal 1, TemporaryData.count
|
38
|
+
get :clear_data
|
39
|
+
assert_equal 0, TemporaryData.count
|
40
|
+
assert_nil session["test_data"]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
8
|
+
|
9
|
+
load "#{File.expand_path('../../..', __FILE__)}/lib/tasks/rails_temporary_data.rake"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class DummyController < ApplicationController
|
2
|
+
|
3
|
+
def set_data
|
4
|
+
set_tmp_data("test_data", params[:data], params[:expires_at])
|
5
|
+
head :ok
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_data
|
9
|
+
@tmp_data = get_tmp_data("test_data")
|
10
|
+
head :ok
|
11
|
+
end
|
12
|
+
|
13
|
+
def clear_data
|
14
|
+
clear_tmp_data("test_data")
|
15
|
+
head :ok
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
|
9
|
+
Bundler.require
|
10
|
+
|
11
|
+
module Dummy
|
12
|
+
class Application < Rails::Application
|
13
|
+
# Settings in config/environments/* take precedence over those specified here.
|
14
|
+
# Application configuration should go into files in config/initializers
|
15
|
+
# -- all .rb files in that directory are automatically loaded.
|
16
|
+
|
17
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
18
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
19
|
+
|
20
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
21
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
22
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
23
|
+
|
24
|
+
# Activate observers that should always be running.
|
25
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
26
|
+
|
27
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
28
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
29
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
30
|
+
|
31
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
32
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
33
|
+
# config.i18n.default_locale = :de
|
34
|
+
|
35
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
36
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
37
|
+
|
38
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
39
|
+
config.encoding = "utf-8"
|
40
|
+
|
41
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
42
|
+
config.filter_parameters += [:password]
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: ":memory:"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
#config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '50777595d4b6041cfca51636cf4e262508f96cc081757729e7123d04a5abdf9e3554e4f519b71106e41c5146a9b07b5affd2e410af1130db3a7f4538b70e2429'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rake db:sessions:create")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get 'short'
|
20
|
+
# post 'toggle'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get 'sold'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get 'recent', :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
# root :to => "welcome#index"
|
52
|
+
|
53
|
+
# See how all your routes lay out with "rake routes"
|
54
|
+
|
55
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
+
match ':controller(/:action(/:id(.:format)))'
|
58
|
+
end
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
File without changes
|
File without changes
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TemporaryDataTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "data column is serialized" do
|
6
|
+
tmp_data = TemporaryData.create(:data => { :first_name => "Vlado", :last_name => "Cingel" })
|
7
|
+
assert "Vlado", tmp_data.data[:first_name]
|
8
|
+
end
|
9
|
+
|
10
|
+
test "expires_at is set before create to time in future if blank (not provided) or set to past" do
|
11
|
+
tmp_data_1 = TemporaryData.create(:data => {})
|
12
|
+
assert tmp_data_1.expires_at > Time.current
|
13
|
+
tmp_data_2 = TemporaryData.create(:data => {}, :expires_at => Time.current - 1.hour)
|
14
|
+
assert tmp_data_2.expires_at > Time.current
|
15
|
+
end
|
16
|
+
|
17
|
+
test "expires_at is not set before create if provided" do
|
18
|
+
expires_at = Time.current + 5.hours
|
19
|
+
tmp_data = TemporaryData.create(:data => {}, :expires_at => expires_at)
|
20
|
+
assert_equal expires_at, tmp_data.expires_at
|
21
|
+
end
|
22
|
+
|
23
|
+
test "it should return all data (including expired) when no scope is defined" do
|
24
|
+
tmp_data_1 = TemporaryData.create(:data => { :tmp_data => 1 }, :expires_at => Time.current + 1.second)
|
25
|
+
tmp_data_2 = TemporaryData.create(:data => { :tmp_data => 2 }, :expires_at => Time.current + 1.hour)
|
26
|
+
sleep 1 # wait for 1 second so tmp_data_1 expires
|
27
|
+
tmp_data = TemporaryData.all
|
28
|
+
assert tmp_data.include?(tmp_data_2)
|
29
|
+
assert tmp_data.include?(tmp_data_1)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "unexpired scope should return only not expired data by default" do
|
33
|
+
tmp_data_1 = TemporaryData.create(:data => { :tmp_data => 1 }, :expires_at => Time.current + 1.second)
|
34
|
+
tmp_data_2 = TemporaryData.create(:data => { :tmp_data => 2 }, :expires_at => Time.current + 1.hour)
|
35
|
+
sleep 1 # wait for 1 second so tmp_data_1 expires
|
36
|
+
tmp_data = TemporaryData.unexpired.all
|
37
|
+
assert tmp_data.include?(tmp_data_2)
|
38
|
+
assert !tmp_data.include?(tmp_data_1)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "not_expired as alias for unexpired" do
|
42
|
+
tmp_data_1 = TemporaryData.create(:data => { :tmp_data => 1 }, :expires_at => Time.current + 1.second)
|
43
|
+
tmp_data_2 = TemporaryData.create(:data => { :tmp_data => 2 }, :expires_at => Time.current + 1.hour)
|
44
|
+
sleep 1 # wait for 1 second so tmp_data_1 expires
|
45
|
+
|
46
|
+
assert_equal TemporaryData.unexpired.all, TemporaryData.not_expired.all
|
47
|
+
end
|
48
|
+
|
49
|
+
test "expired scope should return expired data when no scope is defined" do
|
50
|
+
tmp_data_1 = TemporaryData.create(:data => { :tmp_data => 1 }, :expires_at => Time.current + 1.second)
|
51
|
+
tmp_data_2 = TemporaryData.create(:data => { :tmp_data => 2 }, :expires_at => Time.current + 1.hour)
|
52
|
+
sleep 1 # wait for 1 second so tmp_data_1 expires
|
53
|
+
tmp_data = TemporaryData.expired.all
|
54
|
+
assert !tmp_data.include?(tmp_data_2)
|
55
|
+
assert tmp_data.include?(tmp_data_1)
|
56
|
+
end
|
57
|
+
|
58
|
+
test "delete_expired method should delete all temporary data with expires_at field in the past" do
|
59
|
+
tmp_data_1 = TemporaryData.create(:data => { :tmp_data => 1 }, :expires_at => Time.current + 1.second)
|
60
|
+
tmp_data_2 = TemporaryData.create(:data => { :tmp_data => 2 }, :expires_at => Time.current + 1.hour)
|
61
|
+
assert_equal 2, TemporaryData.unscoped.count
|
62
|
+
|
63
|
+
sleep 1 # wait for 1 second so tmp_data_1 expires
|
64
|
+
TemporaryData.delete_expired
|
65
|
+
assert_equal [tmp_data_2], TemporaryData.all
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'dummy_rails_app/config/environment'
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
ActiveRecord::Migrator.migrate(File.expand_path("../dummy_rails_app/db/migrate/", __FILE__))
|
8
|
+
|
9
|
+
class ActiveSupport::TestCase
|
10
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
11
|
+
#
|
12
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
13
|
+
# -- they do not yet inherit this setting
|
14
|
+
fixtures :all
|
15
|
+
|
16
|
+
# Add more helper methods to be used by all tests here...
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_temporary_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Vlado Cingel
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-21 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: sqlite3
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rails
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Rails engine to simply save temporary data that is too big for session in database
|
63
|
+
email:
|
64
|
+
- vladocingel@gmail.com
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- Gemfile
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- app/models/temporary_data.rb
|
77
|
+
- lib/generators/rails_temporary_data_generator.rb
|
78
|
+
- lib/generators/templates/migration.rb
|
79
|
+
- lib/rails_temporary_data.rb
|
80
|
+
- lib/rails_temporary_data/controller_helpers.rb
|
81
|
+
- lib/rails_temporary_data/engine.rb
|
82
|
+
- lib/rails_temporary_data/version.rb
|
83
|
+
- lib/tasks/rails_temporary_data.rake
|
84
|
+
- rails_temporary_data.gemspec
|
85
|
+
- test/controller_helpers_test.rb
|
86
|
+
- test/dummy_rails_app/Rakefile
|
87
|
+
- test/dummy_rails_app/app/controllers/application_controller.rb
|
88
|
+
- test/dummy_rails_app/app/controllers/dummy_controller.rb
|
89
|
+
- test/dummy_rails_app/app/helpers/application_helper.rb
|
90
|
+
- test/dummy_rails_app/app/views/layouts/application.html.erb
|
91
|
+
- test/dummy_rails_app/config.ru
|
92
|
+
- test/dummy_rails_app/config/application.rb
|
93
|
+
- test/dummy_rails_app/config/boot.rb
|
94
|
+
- test/dummy_rails_app/config/database.yml
|
95
|
+
- test/dummy_rails_app/config/environment.rb
|
96
|
+
- test/dummy_rails_app/config/environments/development.rb
|
97
|
+
- test/dummy_rails_app/config/environments/production.rb
|
98
|
+
- test/dummy_rails_app/config/environments/test.rb
|
99
|
+
- test/dummy_rails_app/config/initializers/backtrace_silencers.rb
|
100
|
+
- test/dummy_rails_app/config/initializers/inflections.rb
|
101
|
+
- test/dummy_rails_app/config/initializers/mime_types.rb
|
102
|
+
- test/dummy_rails_app/config/initializers/secret_token.rb
|
103
|
+
- test/dummy_rails_app/config/initializers/session_store.rb
|
104
|
+
- test/dummy_rails_app/config/locales/en.yml
|
105
|
+
- test/dummy_rails_app/config/routes.rb
|
106
|
+
- test/dummy_rails_app/db/migrate/20120309215634_create_temporary_data.rb
|
107
|
+
- test/dummy_rails_app/db/test.sqlite3
|
108
|
+
- test/dummy_rails_app/public/404.html
|
109
|
+
- test/dummy_rails_app/public/422.html
|
110
|
+
- test/dummy_rails_app/public/500.html
|
111
|
+
- test/dummy_rails_app/public/favicon.ico
|
112
|
+
- test/dummy_rails_app/public/stylesheets/.gitkeep
|
113
|
+
- test/temporary_data_test.rb
|
114
|
+
- test/test_helper.rb
|
115
|
+
homepage: ""
|
116
|
+
licenses: []
|
117
|
+
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project: rails_temporary_data
|
144
|
+
rubygems_version: 1.8.12
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Rails engine to simply save temporary data that is too big for session in database
|
148
|
+
test_files:
|
149
|
+
- test/controller_helpers_test.rb
|
150
|
+
- test/dummy_rails_app/Rakefile
|
151
|
+
- test/dummy_rails_app/app/controllers/application_controller.rb
|
152
|
+
- test/dummy_rails_app/app/controllers/dummy_controller.rb
|
153
|
+
- test/dummy_rails_app/app/helpers/application_helper.rb
|
154
|
+
- test/dummy_rails_app/app/views/layouts/application.html.erb
|
155
|
+
- test/dummy_rails_app/config.ru
|
156
|
+
- test/dummy_rails_app/config/application.rb
|
157
|
+
- test/dummy_rails_app/config/boot.rb
|
158
|
+
- test/dummy_rails_app/config/database.yml
|
159
|
+
- test/dummy_rails_app/config/environment.rb
|
160
|
+
- test/dummy_rails_app/config/environments/development.rb
|
161
|
+
- test/dummy_rails_app/config/environments/production.rb
|
162
|
+
- test/dummy_rails_app/config/environments/test.rb
|
163
|
+
- test/dummy_rails_app/config/initializers/backtrace_silencers.rb
|
164
|
+
- test/dummy_rails_app/config/initializers/inflections.rb
|
165
|
+
- test/dummy_rails_app/config/initializers/mime_types.rb
|
166
|
+
- test/dummy_rails_app/config/initializers/secret_token.rb
|
167
|
+
- test/dummy_rails_app/config/initializers/session_store.rb
|
168
|
+
- test/dummy_rails_app/config/locales/en.yml
|
169
|
+
- test/dummy_rails_app/config/routes.rb
|
170
|
+
- test/dummy_rails_app/db/migrate/20120309215634_create_temporary_data.rb
|
171
|
+
- test/dummy_rails_app/db/test.sqlite3
|
172
|
+
- test/dummy_rails_app/public/404.html
|
173
|
+
- test/dummy_rails_app/public/422.html
|
174
|
+
- test/dummy_rails_app/public/500.html
|
175
|
+
- test/dummy_rails_app/public/favicon.ico
|
176
|
+
- test/dummy_rails_app/public/stylesheets/.gitkeep
|
177
|
+
- test/temporary_data_test.rb
|
178
|
+
- test/test_helper.rb
|
179
|
+
has_rdoc:
|