Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic parameter persistence #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

davidlaprade
Copy link
Contributor

Back in the days of Wombat, some endpoints depended on being able to pass parameters back to the system, e.g. a timestamp of the most recently updated item. This was the point behind the #add_parameter method in spree's EndpointBase, which most of the endpoints have as a dependency. Many of them require the #add_parameter method to function properly, for example:

to name a few.

This attempts to add this functionality to cangaroo, so that anyone using these endpoints really would find cangaroo to be backwards compatible with Wombat.

before(:each) { expect(parameters).to be_empty }
it "returns the persisted params" do
persisted_params = connection.parameters
persisted_params.each do |key, value|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use each_key instead of each.
Unused block argument - value. If it's necessary, use _ or _value as an argument name to indicate that it won't be used.

context "empty param values" do
let(:parameters) { {"a" => nil, "b" => 3, "c" => ""} }
it "removes them" do
expect(subject.send(:request_params)).to eq({"b" => 3})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside { missing.
Redundant curly braces around a hash parameter.
Space inside } missing.

expect(subject.send(:request_params)).to eq({})
end
context "empty param values" do
let(:parameters) { {"a" => nil, "b" => 3, "c" => ""} }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside { missing.
Space inside } missing.

end
it 'does not update the DB if there are no request params' do
expect(parameters).to be_empty
expect{ subject.call }.to_not change{ connection.reload.parameters }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parenthesize the param change{ connection.reload.parameters } to make sure that the block will be associated with the change method call.

end

def request_params
context.parameters.to_h.select{|k,v| v.present?}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between { and | missing.
Unused block argument - k. If it's necessary, use _ or _k as an argument name to indicate that it won't be used.
Space missing after comma.
Space missing inside }.

@davidlaprade davidlaprade force-pushed the dynamic-param-persistence branch 2 times, most recently from 7162aaa to bef1882 Compare March 14, 2018 20:17
connection.reload.parameters
}.from({})
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at block body end.

connection.reload.parameters
}.from({})
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at block body end.

connection.reload.parameters
}.from({})
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at block body end.

@davidlaprade davidlaprade force-pushed the dynamic-param-persistence branch from bef1882 to 9a5cdfd Compare March 14, 2018 20:19
def compatible_http(method, path, args)
case Rails::VERSION::MAJOR
when 4 then self.send(method, path, args[:params], args[:headers])
when 5 then self.send(method, path, args)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant self detected.

# See https://github.com/nebulab/cangaroo/pull/60#issue-175032794
def compatible_http(method, path, args)
case Rails::VERSION::MAJOR
when 4 then self.send(method, path, args[:params], args[:headers])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant self detected.

let(:parameters) { { "different" => "param" } }
it 'does not update the DB' do
expect(connection.parameters.keys).to_not include(parameters.keys.first)
expect{ subject.call }.to_not change{ connection.reload.parameters.with_indifferent_access }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parenthesize the param change{ connection.reload.parameters.with_indifferent_access } to make sure that the block will be associated with the change method call.

@davidlaprade davidlaprade force-pushed the dynamic-param-persistence branch from 6377df2 to 5e38aff Compare March 15, 2018 13:38
@davidlaprade
Copy link
Contributor Author

@bricesanchez @AlessioRocco

Have you guys had a chance to look at this? I've had it running in production for a couple months now without issue. Anything I can do to help keep this moving along?

@AlessioRocco
Copy link
Member

@bricesanchez it seems ok for me, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants