Skip to content

Commit

Permalink
Add deprecation warning for options in custom request methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vaihtovirta authored and zacharywelch committed Oct 14, 2019
1 parent 76f1b7b commit 991ce1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
6 changes: 6 additions & 0 deletions lib/her/model/http.rb
Expand Up @@ -98,6 +98,12 @@ def #{method}_resource(path, params={})
def custom_#{method}(*paths)
metaclass = (class << self; self; end)
# TODO: Remove this check after January 2020
if paths.last.is_a?(Hash)
warn("[DEPRECATION] options for custom request methods are deprecated and will be removed on or after January 2020.")
paths.pop
end
paths.each do |path|
metaclass.send(:define_method, path) do |*params|
params = params.first || Hash.new
Expand Down
46 changes: 28 additions & 18 deletions spec/model/http_spec.rb
Expand Up @@ -158,33 +158,43 @@
subject { Foo::User }

describe :custom_get do
context "without cache" do
before { Foo::User.custom_get :popular, :recent }
it { is_expected.to respond_to(:popular) }
it { is_expected.to respond_to(:recent) }
before do
Foo::User.custom_get :popular, :recent
end

context "making the HTTP request" do
subject { Foo::User.popular }
it { is_expected.to respond_to(:popular) }
it { is_expected.to respond_to(:recent) }

describe "#length" do
subject { super().length }
it { is_expected.to eq(2) }
end
end
it "makes HTTP request" do
expect(Foo::User.popular.length).to be 2
end
end

describe :custom_post do
before { Foo::User.custom_post :from_default }
before do
Foo::User.custom_post :from_default
end

it { is_expected.to respond_to(:from_default) }

context "making the HTTP request" do
subject { Foo::User.from_default(name: "Tobias Fünke") }
it "makes HTTP request" do
user = Foo::User.from_default(name: "Tobias Fünke")
expect(user.id).to be 4
end
end

describe "#id" do
subject { super().id }
it { is_expected.to eq(4) }
end
context "with options" do
before do
allow(Foo::User).to receive(:warn)
Foo::User.custom_get :popular, foo: "bar"
end

it "issues DEPRECATION warning" do
expect(Foo::User).to have_received(:warn).with("[DEPRECATION] options for custom request methods are deprecated and will be removed on or after January 2020.")
end

it "makes HTTP request" do
expect(Foo::User.popular.length).to be 2
end
end
end
Expand Down

0 comments on commit 991ce1a

Please sign in to comment.