Skip to content

Commit

Permalink
Merge pull request #17 from dziemian007/proc_bind_fix
Browse files Browse the repository at this point in the history
Fix Proc#bind being depreciated in activesupport 4.2
  • Loading branch information
hubertlepicki committed Feb 20, 2015
2 parents 1958118 + 1f39c4b commit f5c66de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/controllers/translator/translations_controller.rb
Expand Up @@ -78,7 +78,7 @@ def destroy
private

def auth
Translator.auth_handler.bind(self).call if Translator.auth_handler.is_a? Proc
self.instance_eval(&Translator.auth_handler) if Translator.auth_handler.is_a? Proc
end

def paginate(collection)
Expand All @@ -89,4 +89,3 @@ def paginate(collection)
end
end
end

32 changes: 32 additions & 0 deletions spec/controllers/translations_controller_spec.rb
@@ -0,0 +1,32 @@
# encoding: UTF-8
require 'spec_helper'

RSpec.describe Translator::TranslationsController do

before :all do
conn = Mongo::Connection.new.db("translator_test").collection("translations")
Translator.current_store = Translator::MongoStore.new(conn)
I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new)
end

after :all do
Translator.auth_handler = nil
end

describe "GET index" do
context "auth_handler" do
it "responds OK with no auth proc" do
get :index, use_route: '/'
expect(response.status).to eq(200)
end

it "responds 401 with auth proc defined" do
Translator.auth_handler = proc {
head 401
}
get :index, use_route: '/'
expect(response.status).to eq(401)
end
end
end
end

0 comments on commit f5c66de

Please sign in to comment.