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

Restore Ruby 1.8.7 compatibility with lambda styles etc. #272

Merged
merged 1 commit into from
Aug 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
language: ruby
rvm:
- 1.8.7
- 1.9.3
- 2.0.0
- 2.1.1
gemfile:
- Gemfile.rails32
- Gemfile.rails40
- Gemfile.rails41
matrix:
exclude:
- rvm: 1.8.7
gemfile: Gemfile.rails40
- rvm: 1.8.7
gemfile: Gemfile.rails41
4 changes: 2 additions & 2 deletions lib/apipie/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def initialize(param_description, argument, options={})
end

def validate(values)
return false unless process_value(values).respond_to?(:each)
return false unless process_value(values).respond_to?(:each) && !process_value(values).is_a?(String)
process_value(values).all? { |v| validate_item(v)}
end

Expand All @@ -175,7 +175,7 @@ def description
"Must be an array of #{items}"
end

def self.build(param_description, argument, options={}, block)
def self.build(param_description, argument, options, block)
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this change affect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing AFAICT, as https://github.com/domcleal/apipie-rails/blob/ruby18/lib/apipie/validator.rb#L24 calls this with the options argument every time.

if argument == Array && !block.is_a?(Proc)
self.new(param_description, argument, options)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/extractor/middleware_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "spec_helper"

describe Apipie::Extractor::Recorder::Middleware do
let(:app) { ->(env) { [200, env, "app"] } }
let(:app) { lambda { |env| [200, env, "app"] } }
let(:stack) { Apipie::Extractor::Recorder::Middleware.new(app) }
let(:request) { Rack::MockRequest.new(stack) }
let(:response) { request.get('/') }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/method_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
end

it "should return the deprecated flag when provided" do
dsl_data[:api_args] = [[:GET, "/foo/bar", "description", :deprecated => true]]
dsl_data[:api_args] = [[:GET, "/foo/bar", "description", {:deprecated => true}]]
method = Apipie::MethodDescription.new(:a, @resource, dsl_data)
method.method_apis_to_json.first[:deprecated].should == true
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/validators/array_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Apipie::Validator
end

context "with a constraint on items type" do
let(:validator) { ArrayValidator.new(param_desc, Array, of: String) }
let(:validator) { ArrayValidator.new(param_desc, Array, :of => String) }

it "accepts array of specified type" do
expect(validator.validate(['string1', 'string2'])).to eq(true)
Expand All @@ -40,7 +40,7 @@ module Apipie::Validator
end

context "with a constraint on items value" do
let(:validator) { ArrayValidator.new(param_desc, Array, in: [42, 'string', true]) }
let(:validator) { ArrayValidator.new(param_desc, Array, :in => [42, 'string', true]) }

it "accepts array of valid values" do
expect(validator.validate([42, 'string'])).to eq(true)
Expand All @@ -55,7 +55,7 @@ module Apipie::Validator
end

it "accepts a proc as list of valid values" do
validator = ArrayValidator.new(param_desc, Array, in: -> { [42, 'string', true] })
validator = ArrayValidator.new(param_desc, Array, :in => lambda { [42, 'string', true] })
expect(validator.validate([42, 'string'])).to eq(true)
expect(validator.validate([42, 'string', 'foo'])).to eq(false)
end
Expand Down