Skip to content

Commit

Permalink
Sketching the rails-centric bits
Browse files Browse the repository at this point in the history
  • Loading branch information
jcasimir committed Oct 19, 2012
1 parent 0866252 commit 6290fb6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
10 changes: 9 additions & 1 deletion lib/locale_setter.rb
@@ -1,5 +1,13 @@
require "locale_setter/version"

module LocaleSetter
# Your code goes here...
def self.included(controller)
if controller.respond_to?(:before_filter)
controller.before_filter :set_locale
end
end

def default_url_options(options)
{:locale => ""}.merge(options)
end
end
39 changes: 38 additions & 1 deletion spec/locale_setter_spec.rb
Expand Up @@ -2,6 +2,43 @@

describe LocaleSetter do
it "exists" do
expect{ LocaleSetter.new }.to_not raise_error
expect{ LocaleSetter }.to_not raise_error
end

class BareController; end

describe ".included" do

it "sets a before filter" do
BareController.should_receive(:before_filter).with(:set_locale)
BareController.send(:include, LocaleSetter)
end

it "skips setting the before_filter if not supported" do
expect{ BareController.send(:include, LocaleSetter) }.to_not raise_error
end
end

class Controller
include LocaleSetter
end

describe "#default_url_options" do
let(:controller){ Controller.new }

it "adds a :locale key" do
controller.default_url_options({})[:locale].should be
end

it "builds on passed in options" do
result = controller.default_url_options({:test => true})
result[:test].should be
result[:locale].should be
end

it "defers to a passed in locale" do
result = controller.default_url_options({:locale => 'abc'})
result[:locale].should == 'abc'
end
end
end

0 comments on commit 6290fb6

Please sign in to comment.