Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reset and default_ttl features passing
- Loading branch information
1 parent
16bb35e
commit f9e5d19
Showing
10 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
rvm 1.8.7@wallet --create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,98 @@ | |||
PATH | |||
remote: . | |||
specs: | |||
wallet (1.0.0.beta.1) | |||
rails (~> 3.0) | |||
|
|||
GEM | |||
remote: http://rubygems.org/ | |||
specs: | |||
abstract (1.0.0) | |||
actionmailer (3.0.8) | |||
actionpack (= 3.0.8) | |||
mail (~> 2.2.19) | |||
actionpack (3.0.8) | |||
activemodel (= 3.0.8) | |||
activesupport (= 3.0.8) | |||
builder (~> 2.1.2) | |||
erubis (~> 2.6.6) | |||
i18n (~> 0.5.0) | |||
rack (~> 1.2.1) | |||
rack-mount (~> 0.6.14) | |||
rack-test (~> 0.5.7) | |||
tzinfo (~> 0.3.23) | |||
activemodel (3.0.8) | |||
activesupport (= 3.0.8) | |||
builder (~> 2.1.2) | |||
i18n (~> 0.5.0) | |||
activerecord (3.0.8) | |||
activemodel (= 3.0.8) | |||
activesupport (= 3.0.8) | |||
arel (~> 2.0.10) | |||
tzinfo (~> 0.3.23) | |||
activeresource (3.0.8) | |||
activemodel (= 3.0.8) | |||
activesupport (= 3.0.8) | |||
activesupport (3.0.8) | |||
arel (2.0.10) | |||
builder (2.1.2) | |||
cucumber (0.10.6) | |||
builder (>= 2.1.2) | |||
diff-lcs (>= 1.1.2) | |||
gherkin (~> 2.4.0) | |||
json (>= 1.4.6) | |||
term-ansicolor (>= 1.0.5) | |||
diff-lcs (1.1.2) | |||
erubis (2.6.6) | |||
abstract (>= 1.0.0) | |||
gherkin (2.4.0) | |||
json (>= 1.4.6) | |||
i18n (0.5.0) | |||
json (1.5.1) | |||
mail (2.2.19) | |||
activesupport (>= 2.3.6) | |||
i18n (>= 0.4.0) | |||
mime-types (~> 1.16) | |||
treetop (~> 1.4.8) | |||
mime-types (1.16) | |||
polyglot (0.3.1) | |||
rack (1.2.3) | |||
rack-mount (0.6.14) | |||
rack (>= 1.0.0) | |||
rack-test (0.5.7) | |||
rack (>= 1.0) | |||
rails (3.0.8) | |||
actionmailer (= 3.0.8) | |||
actionpack (= 3.0.8) | |||
activerecord (= 3.0.8) | |||
activeresource (= 3.0.8) | |||
activesupport (= 3.0.8) | |||
bundler (~> 1.0) | |||
railties (= 3.0.8) | |||
railties (3.0.8) | |||
actionpack (= 3.0.8) | |||
activesupport (= 3.0.8) | |||
rake (>= 0.8.7) | |||
thor (~> 0.14.4) | |||
rake (0.9.2) | |||
rspec (2.6.0) | |||
rspec-core (~> 2.6.0) | |||
rspec-expectations (~> 2.6.0) | |||
rspec-mocks (~> 2.6.0) | |||
rspec-core (2.6.4) | |||
rspec-expectations (2.6.0) | |||
diff-lcs (~> 1.1.2) | |||
rspec-mocks (2.6.0) | |||
term-ansicolor (1.0.5) | |||
thor (0.14.6) | |||
treetop (1.4.9) | |||
polyglot (>= 0.3.1) | |||
tzinfo (0.3.27) | |||
|
|||
PLATFORMS | |||
ruby | |||
|
|||
DEPENDENCIES | |||
cucumber (~> 0.10) | |||
rspec (~> 2.0) | |||
wallet! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
Feature: | |||
As a programmer | |||
I want a configurable TTL default | |||
So that I can provide a default TTL for my action cache | |||
|
|||
Scenario: TTL defaults to 10 minutes | |||
Given I have not configured Wallet | |||
Then the default TTL should be 10 minutes | |||
|
|||
Scenario: Change the default TTL | |||
When I set the default TTL to 20 minutes | |||
Then all cache TTL's should default to 20 minutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
Feature: Reset Wallet | |||
As a programmer | |||
I want a way to reset the Wallet configuration | |||
So that I can easily test it | |||
|
|||
Scenario: resetting the Wallet back to it's factory settings | |||
Given I have configured Wallet | |||
When I reset Wallet | |||
Then Wallet should return to it's default settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
Given /^I have not configured Wallet$/ do | |||
end | |||
|
|||
Then /^the default TTL should be (\d+) minutes$/ do |num| | |||
Wallet.default_ttl.should == num.to_i.minutes | |||
end | |||
|
|||
When /^I set the default TTL to (\d+) minutes$/ do |num| | |||
Wallet.default_ttl = num.to_i.minutes | |||
end | |||
|
|||
Then /^all cache TTL's should default to (\d+) minutes$/ do |num| | |||
Wallet.default_ttl.should == num.to_i.minutes | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
Given /^I have configured Wallet$/ do | |||
Wallet.default_ttl = 100.minutes | |||
end | |||
|
|||
When /^I reset Wallet$/ do | |||
Wallet.reset! | |||
end | |||
|
|||
Then /^Wallet should return to it's default settings$/ do | |||
Wallet.default_ttl.should == 10.minutes | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
$LOAD_PATH.unshift './lib' | |||
require 'wallet' | |||
require 'cucumber/rspec/doubles' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
require 'wallet/wallet' | |||
require 'active_support/all' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
module Wallet | |||
extend self | |||
attr_accessor :default_ttl | |||
|
|||
def default_ttl | |||
@default_ttl ||= 10.minutes | |||
end | |||
|
|||
def reset! | |||
@default_ttl = nil | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
# Wallet | |||
|
|||
Wallet, a simple ruby DSL for centralizing action cache configuration inside your Rails app. | |||
|
|||
## Installation | |||
|
|||
Wallet is a gem, available from http://rubygems.org. | |||
|
|||
Add the following to your Rails 3 app's Gemfile: | |||
|
|||
gem 'wallet', '~> 1.0' | |||
|
|||
## Usage | |||
|
|||
Let's imagine your app has a controller `HomeController`, and you want to action cache all of the | |||
actions inside of it. First, create a `config/wallet.rb` inside your rails root, then open your `Wallet` and add some `cash`: | |||
|
|||
Wallet.open do | |||
cash :home | |||
end | |||
|
|||
Next, open your `ApplicationController`, and add the following into it: | |||
|
|||
class ApplicationController < ActionController::Base | |||
include Wallet::Cash | |||
cash! | |||
end | |||
|
|||
The `cash!` method will setup action caching for your controllers (if they have any cache configuration in Wallet). | |||
|
|||
With this code in place, Rails will action cache every action inside your home controller for the default TTL (time-to-live) duration: 10 minutes. You can change the default ttl by passing a duration to the `default_ttl` method: | |||
|
|||
Wallet.default_ttl = 2.minutes | |||
|
|||
Now, suppose we have another controller, `ArticlesController`, and we want to cache the `show` and `index` actions on it for a duration of 20 minutes. Simple! | |||
|
|||
Wallet.open do | |||
cash :articles, :for => 20.minutes do | |||
show | |||
index | |||
end | |||
end | |||
|
|||
This will cache only the `show` and `index` actions on the `ArticlesController`. | |||
|
|||
Now imagine we've added a third action, `comments`, to our `ArticlesController`, and we want to cache it for only 1 minute: | |||
|
|||
Wallet.open do | |||
cash :articles, :for => 20.minutes do | |||
show | |||
index | |||
comments 1.minute | |||
end | |||
end | |||
|
|||
## Before filters and action caching | |||
|
|||
Sometimes, even though an action is cached, you want a before filter to run before Rails try's to serve out the cached response. Authentication is one common use case. You can accomplish this with Wallet by simply calling `cash!` after the before filters: | |||
|
|||
class ApplicationController < ActionController::Base | |||
include Wallet::Cash | |||
|
|||
before_filter :authentication | |||
cash! | |||
|
|||
private | |||
def authentication | |||
#... | |||
end | |||
end | |||
|
|||
Now, the `authentication` method will run before your before filters. | |||
|
|||
## Engines | |||
|
|||
Wallet plays nice with engines. If you'd like to use Wallet inside your engine, create a `config/wallet.rb` file inside your engine, then include `Wallet::Railtie` inside your Engine railtie: | |||
|
|||
module Comments | |||
class Engine < Rails::Engine | |||
include Wallet::Railtie | |||
end | |||
end | |||
|
|||
Now, Rails will load the `config/wallet.rb` inside your engine before your controllers load. |