Skip to content

Commit

Permalink
Raise NameError when there is no current_user
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Vieira committed Mar 18, 2015
1 parent 66f9d72 commit 87aed05
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
### Arcane **1.1.1** [head][current] - 2013-07-17
### Arcane **1.2.0** [head] - 2015-03-18
* **[breaking change]** If `current_user` is not
specified `current_params_user` will raise a
`NameError`.

### Arcane **1.1.1** [current] - 2013-07-17
* **[bugfix]** Handle nil paramaters params as
@caulfield suggested in pull request #7. Thank you.
This doesn't break any functionality other than expecting
Expand Down
2 changes: 1 addition & 1 deletion lib/arcane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Arcane
end

def current_params_user
respond_to?(:current_user) ? current_user : nil
current_user
end

def params
Expand Down
23 changes: 23 additions & 0 deletions spec/arcane_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
require 'spec_helper'

class MockController
attr_accessor :request, :user
def initialize(request, user)
@request, @user = request, user
end
end

class MockNoUserController
attr_accessor :request
def initialize(request)
@request = request
end
end

describe Arcane do

let(:user) { double(name: :user) }
Expand Down Expand Up @@ -32,4 +46,13 @@
end
end

describe "#current_params_user" do
context "when there is no current user" do
let(:controller) { MockNoUserController.new(request).tap { |c| c.extend(Arcane) } }
it "should raise a no method error" do
expect { controller.current_params_user }.to raise_exception NameError
end
end
end

end

0 comments on commit 87aed05

Please sign in to comment.