diff --git a/.travis.yml b/.travis.yml index cb1e575..3c4a0f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,19 @@ language: ruby sudo: false gemfile: - - gemfiles/Gemfile32.ci - - gemfiles/Gemfile40.ci - - gemfiles/Gemfile41.ci - - gemfiles/Gemfile42.ci -install: bundle install -j4 --path vendor/bundle + - gemfiles/rails_32.gemfile + - gemfiles/rails_40.gemfile + - gemfiles/rails_41.gemfile + - gemfiles/rails_42.gemfile rvm: - 1.9.3 - 2.0.0 - - 2.1.1 + - 2.1.5 + - 2.2.0 +matrix: + exclude: + # NOTE : incompatible + - rvm: 2.2.0 + gemfile: gemfiles/rails_32.gemfile +install: bundle install -j4 --path vendor/bundle + diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..387bb79 --- /dev/null +++ b/Appraisals @@ -0,0 +1,16 @@ +appraise 'rails-32' do + gem 'rails', '~> 3.2.21' +end + +appraise 'rails-40' do + gem 'rails', '~> 4.0.13' +end + +appraise 'rails-41' do + gem 'rails', '~> 4.1.9' +end + +appraise 'rails-42' do + gem 'rails', '~> 4.2.0' +end + diff --git a/Gemfile b/Gemfile index 685c449..7b05d35 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,9 @@ group :development do gem 'highline' # gem 'coderay', path: '../coderay' + # multiple rails versions support + gem 'appraisal' + # build template static # run `rake assets:precompile` # to get bundled application.(js|css) @@ -27,5 +30,6 @@ group :development do gem 'bootstrap-sass', '~> 3.1.1' gem 'jquery-rails' gem 'remotipart' - gem "launchy" + gem 'launchy' end + diff --git a/features/atom_persistent_within_the_same_type.feature b/features/atom_persistent_within_the_same_type.feature index 3b2aa07..3407012 100644 --- a/features/atom_persistent_within_the_same_type.feature +++ b/features/atom_persistent_within_the_same_type.feature @@ -51,9 +51,9 @@ Feature: atom persistent within test suite method: PATCH path_info: "/api/v2/users/100" path_params: - id: '100' controller: api/v2/users action: update + id: '100' """ Scenario: json schema tests response parameters and keep atom unchanged using "users/update" @@ -129,8 +129,9 @@ Feature: atom persistent within test suite method: PATCH path_info: "/api/v2/users/100" path_params: - id: '100' controller: api/v2/users action: update + id: '100' """ + diff --git a/features/controller_nested_schema_scaffolding.feature b/features/controller_nested_schema_scaffolding.feature index 44febbf..31c04df 100644 --- a/features/controller_nested_schema_scaffolding.feature +++ b/features/controller_nested_schema_scaffolding.feature @@ -71,10 +71,11 @@ Feature: controller nested schema scaffolding method: GET path_info: "/api/v1/users/1/repos.json" path_params: - user_id: '1' controller: api/v1/repos action: index + user_id: '1' query_params: limit: 1 """ + diff --git a/features/controller_schema_scaffolding.feature b/features/controller_schema_scaffolding.feature index 45249c0..b8d18bf 100644 --- a/features/controller_schema_scaffolding.feature +++ b/features/controller_schema_scaffolding.feature @@ -63,8 +63,9 @@ Feature: controller schema scaffolding method: GET path_info: "/api/v1/users/1.json" path_params: - id: '1' controller: api/v1/users action: show + id: '1' """ + diff --git a/features/dereferencing_through_inlining.feature b/features/dereferencing_through_inlining.feature index b0cd3bb..19a4900 100644 --- a/features/dereferencing_through_inlining.feature +++ b/features/dereferencing_through_inlining.feature @@ -23,9 +23,9 @@ Feature: $ref defererencing through inlining method: PATCH path_info: "/api/v3/users/1" path_params: - id: '1' controller: api/v3/users action: update + id: '1' """ And a file named "lurker/definitions/user_request_parameters.json" with: @@ -100,3 +100,4 @@ Feature: $ref defererencing through inlining ] } """ + diff --git a/features/html_generation.feature b/features/html_generation.feature index c9f515d..65f00a2 100644 --- a/features/html_generation.feature +++ b/features/html_generation.feature @@ -38,8 +38,8 @@ Feature: html generation method: POST path_info: "/api/v1/users.json" path_params: - action: create controller: api/v1/users + action: create """ When I successfully run `bin/lurker convert` @@ -73,3 +73,4 @@ Feature: html generation And I submit it Then I should see JSON response with "can't be blank" + diff --git a/features/minitest.feature b/features/minitest.feature index ff918a3..bf52c03 100644 --- a/features/minitest.feature +++ b/features/minitest.feature @@ -57,8 +57,8 @@ Feature: minitest method: DELETE path_info: "/api/v1/users/1/repos/1.json" path_params: - action: destroy controller: api/v1/repos + action: destroy user_id: '1' id: '1' @@ -100,8 +100,8 @@ Feature: minitest path_info: "/api/v1/users/1" method: PATCH path_params: - action: update controller: api/v1/users + action: update id: 1 """ @@ -136,3 +136,4 @@ Feature: minitest """ 1 (runs|tests), 1 assertions, 0 failures, 1 errors, 0 skips """ + diff --git a/features/multidomain_support.feature b/features/multidomain_support.feature index a2a0e06..9d4cc18 100644 --- a/features/multidomain_support.feature +++ b/features/multidomain_support.feature @@ -47,8 +47,8 @@ Feature: mutidomain support method: DELETE path_info: "/api/v1/users/1.json" path_params: - action: destroy controller: api/v1/users + action: destroy id: 1 """ diff --git a/features/multitype_request_support.feature b/features/multitype_request_support.feature index 8d65fa8..a924105 100644 --- a/features/multitype_request_support.feature +++ b/features/multitype_request_support.feature @@ -52,9 +52,9 @@ Feature: multitype request support method: PATCH path_info: "/api/v2/users/1" path_params: - id: '1' controller: api/v2/users action: update + id: '1' """ Scenario: json schema tests response parameters and update request parameters using "users/update" @@ -130,8 +130,9 @@ Feature: multitype request support method: PATCH path_info: "/api/v2/users/1" path_params: - id: '1' controller: api/v2/users action: update + id: '1' """ + diff --git a/features/partials.feature b/features/partials.feature index 7099271..83e204c 100644 --- a/features/partials.feature +++ b/features/partials.feature @@ -61,8 +61,8 @@ Feature: partials method: POST path_info: "/api/v1/users/1/repos.json" path_params: - action: create controller: api/v1/repos + action: create user_id: '1' """ @@ -77,7 +77,7 @@ Feature: partials it "creates a new repo" do expect { - post "api/v1/users/#{user.id}/repos.json", repo: { name: 'new-gem' } + post "/api/v1/users/#{user.id}/repos.json", repo: { name: 'new-gem' } expect(response).to be_success expect(JSON.parse(response.body)['user']).to eq JSON.parse(user.to_json) }.to change { Repo.count } .by(1) @@ -97,3 +97,4 @@ Feature: partials create index.html create api/v1/users/__user_id/repos-POST.html """ + diff --git a/features/request_nested_schema_scaffolding.feature b/features/request_nested_schema_scaffolding.feature index f18944b..d71aa15 100644 --- a/features/request_nested_schema_scaffolding.feature +++ b/features/request_nested_schema_scaffolding.feature @@ -8,7 +8,6 @@ Feature: request nested schema scaffolding require "spec_helper" describe Api::V1::ReposController, :lurker do - let!(:user) do User.where(name: 'razum2um').first_or_create!.tap do |u| u.repos.first_or_create!(name: 'lurker') @@ -16,7 +15,7 @@ Feature: request nested schema scaffolding end it "shows a user's repo" do - get "api/v1/users/#{user.id}/repos/#{user.repos.first.id}.json" + get "/api/v1/users/#{user.id}/repos/#{user.repos.first.id}.json" expect(response).to be_success end end @@ -62,9 +61,10 @@ Feature: request nested schema scaffolding method: GET path_info: "/api/v1/users/1/repos/1.json" path_params: - action: show controller: api/v1/repos + action: show user_id: '1' id: '1' """ + diff --git a/features/request_schema_scaffolding.feature b/features/request_schema_scaffolding.feature index d609f44..293ba3e 100644 --- a/features/request_schema_scaffolding.feature +++ b/features/request_schema_scaffolding.feature @@ -19,7 +19,7 @@ Feature: request schema scaffolding end it "lists all the users" do - get "api/v1/users.json?limit=1" + get "/api/v1/users.json?limit=1" expect(response).to be_success expect(JSON.parse(response.body).size).to eq 1 end @@ -72,9 +72,10 @@ Feature: request schema scaffolding method: GET path_info: "/api/v1/users.json" path_params: - action: index controller: api/v1/users + action: index query_params: limit: '1' """ + diff --git a/features/schema_suffixes.feature b/features/schema_suffixes.feature index 6c424e0..8f33309 100644 --- a/features/schema_suffixes.feature +++ b/features/schema_suffixes.feature @@ -49,8 +49,8 @@ Feature: schema suffixes path_info: "/api/v1/users/razum2um/repos/lurker.json" method: PATCH path_params: - action: update controller: api/v1/repos + action: update user_id: razum2um id: lurker """ @@ -120,8 +120,8 @@ Feature: schema suffixes method: PATCH suffix: 'failed' path_params: - action: update controller: api/v1/repos + action: update user_id: razum2um id: lurker """ diff --git a/features/schema_updating_within_test_suite.feature b/features/schema_updating_within_test_suite.feature index 784aee2..d35a7c4 100644 --- a/features/schema_updating_within_test_suite.feature +++ b/features/schema_updating_within_test_suite.feature @@ -54,9 +54,9 @@ Feature: schema updating within test suite method: PATCH path_info: "/api/v2/users/1" path_params: - id: '1' controller: api/v2/users action: update + id: '1' """ Scenario: json schema tests response parameters and request parameters and show errors from both using "users/update" @@ -166,8 +166,9 @@ Feature: schema updating within test suite method: PATCH path_info: "/api/v2/users/1" path_params: - id: '1' controller: api/v2/users action: update + id: '1' """ + diff --git a/features/test_endpoint.feature b/features/test_endpoint.feature index fd0e2dc..cc900fb 100644 --- a/features/test_endpoint.feature +++ b/features/test_endpoint.feature @@ -48,8 +48,8 @@ Feature: test endpoint path_info: "/api/v1/users/1" method: PATCH path_params: - action: update controller: api/v1/users + action: update id: 1 """ @@ -75,35 +75,6 @@ Feature: test endpoint When I run `bin/rspec spec/controllers/api/v1/users_controller_spec.rb` Then the example should pass - Scenario: json schema tests request parameters and tell what fails using "users/update" - Given a file named "spec/controllers/api/v1/users_controller_spec.rb" with: - """ruby - require "spec_helper" - - describe Api::V1::UsersController, :lurker do - render_views - - let(:user) do - User.where(name: 'razum2um').first_or_create! - end - - it "updates a user" do - patch :update, id: user.id, user: { name: 1 }, format: 'json' - expect(response).to be_success - end - end - """ - - When I run `bin/rspec spec/controllers/api/v1/users_controller_spec.rb` - Then the output should contain failures: - """ - Lurker::ValidationError: - Response - The property '#/name' of type Fixnum did not match the following type: string - - 1 example, 1 failure - """ - Scenario: json schema tests response parameters and tell what fails using "users/update" Given a file named "spec/controllers/api/v1/users_controller_blank_spec.rb" with: """ruby @@ -132,3 +103,4 @@ Feature: test endpoint 1 example, 1 failure """ + diff --git a/gemfiles/Gemfile32.ci b/gemfiles/Gemfile32.ci deleted file mode 100644 index 1e65739..0000000 --- a/gemfiles/Gemfile32.ci +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in lurker.gemspec -gemspec path: '../' - -gem 'rails', '~> 3.2.17' diff --git a/gemfiles/Gemfile40.ci b/gemfiles/Gemfile40.ci deleted file mode 100644 index 0e43977..0000000 --- a/gemfiles/Gemfile40.ci +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in lurker.gemspec -gemspec path: '../' - -gem 'rails', '~> 4.0.4' diff --git a/gemfiles/Gemfile41.ci b/gemfiles/Gemfile41.ci deleted file mode 100644 index 5a99a7e..0000000 --- a/gemfiles/Gemfile41.ci +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in lurker.gemspec -gemspec path: '../' - -gem 'rails', '~> 4.1.0' diff --git a/gemfiles/Gemfile42.ci b/gemfiles/Gemfile42.ci deleted file mode 100644 index 10012ef..0000000 --- a/gemfiles/Gemfile42.ci +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in lurker.gemspec -gemspec path: '../' - -gem 'rails', '~> 4.2.0' diff --git a/gemfiles/rails_32.gemfile b/gemfiles/rails_32.gemfile new file mode 100644 index 0000000..c4029a6 --- /dev/null +++ b/gemfiles/rails_32.gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in lurker.gemspec +gemspec path: "../" + +gem "rails", "~> 3.2.21" + diff --git a/gemfiles/rails_40.gemfile b/gemfiles/rails_40.gemfile new file mode 100644 index 0000000..14ae5c8 --- /dev/null +++ b/gemfiles/rails_40.gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in lurker.gemspec +gemspec path: "../" + +gem "rails", "~> 4.0.13" + diff --git a/gemfiles/rails_41.gemfile b/gemfiles/rails_41.gemfile new file mode 100644 index 0000000..969e076 --- /dev/null +++ b/gemfiles/rails_41.gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in lurker.gemspec +gemspec path: "../" + +gem "rails", "~> 4.1.9" + diff --git a/gemfiles/rails_42.gemfile b/gemfiles/rails_42.gemfile new file mode 100644 index 0000000..80719e6 --- /dev/null +++ b/gemfiles/rails_42.gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in lurker.gemspec +gemspec path: "../" + +gem "rails", "~> 4.2.0" + diff --git a/lib/lurker/server.rb b/lib/lurker/server.rb index 6b8511e..16d9f4b 100644 --- a/lib/lurker/server.rb +++ b/lib/lurker/server.rb @@ -47,8 +47,11 @@ def self.to_rack(options = {}) :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially end - Lurker.const_set("Rack_#{rand 10}_#{Time.now.to_i}", cls) + + rack_name = "Rack_#{srand}_#{Time.now.strftime('%s%N')}" + Lurker.const_set(rack_name, cls) cls end end end + diff --git a/lib/lurker/spec_helper/rails.rb b/lib/lurker/spec_helper/rails.rb index a536eb6..cb8e651 100644 --- a/lib/lurker/spec_helper/rails.rb +++ b/lib/lurker/spec_helper/rails.rb @@ -1,3 +1,4 @@ +require 'active_support/concern' require 'lurker/spy' module Lurker @@ -38,3 +39,4 @@ def new(*) if defined?(ActionController::TestCase::Behavior) ActionController::TestCase::Behavior.send :include, Lurker::SpecHelper::Rails end + diff --git a/lib/lurker/spy.rb b/lib/lurker/spy.rb index dda909d..82b2561 100644 --- a/lib/lurker/spy.rb +++ b/lib/lurker/spy.rb @@ -42,7 +42,7 @@ def endpoint_path def extensions extensions = { - path_params: request.path_params, + path_params: reordered_request_path_params, path_info: request.path_info, method: request.verb, } @@ -88,5 +88,19 @@ def self.enabled? def self.current Thread.current[:lurker_spy] end + + private + + def reordered_request_path_params + other_params = request.path_params.reject do |k, _| + k == 'controller' || k == 'action' + end + + { + 'controller' => request.path_params['controller'], + 'action' => request.path_params['action'] + }.merge!(other_params) + end end end + diff --git a/lurker.gemspec b/lurker.gemspec index 1fff8e4..2cda938 100644 --- a/lurker.gemspec +++ b/lurker.gemspec @@ -6,8 +6,8 @@ require "lurker/version" Gem::Specification.new do |spec| spec.name = "lurker" spec.version = Lurker::VERSION - spec.authors = ["Vlad Bokov"] - spec.email = ["bokov.vlad@gmail.com"] + spec.authors = ["Vlad Bokov", "Sergey Fedorov"] + spec.email = ["bokov.vlad@gmail.com", "oni.strech@gmail.com"] spec.summary = %q{Get pretty, documented and visible API} spec.description = %q{The new de-facto for API testing your Rails application} spec.homepage = "http://github.com/razum2um/lurker" @@ -54,4 +54,10 @@ Gem::Specification.new do |spec| spec.add_development_dependency("execjs", "~> 2.0") spec.add_development_dependency("pdfkit", "~> 0.6") spec.add_development_dependency("wkhtmltopdf-binary", "~> 0.9") + + if RUBY_VERSION >= "2.2.0" + # FIXME : this gem are needed to ruby 2.2.0 + spec.add_development_dependency("test-unit", "~> 3.0") + end end + diff --git a/templates/generate_stuff.rb b/templates/generate_stuff.rb index 99757cc..742b99e 100644 --- a/templates/generate_stuff.rb +++ b/templates/generate_stuff.rb @@ -294,12 +294,12 @@ class Api::V#{version}::ReposController < Api::V1::ReposController; end end require 'rack/cors' # FIXME - config.middleware.insert 0, Rack::Cors do + config.middleware.insert 0, "Rack::Cors" do allow do - origins 'localhost:3000', '127.0.0.1:3000', 'razum2um.github.io', 'lurker-app.herokuapp.com', 'lurker.razum2um.me' + origins %w[localhost:3000 127.0.0.1:3000 razum2um.github.io lurker-app.herokuapp.com lurker.razum2um.me] resource '*', :headers => :any, - :methods => :any, + :methods => [:get, :post, :delete, :put, :options, :head], :credentials => false, :expose => %w[Etag Server X-Content-Type-Options X-Frame-Options X-Request-Id X-Runtime X-Xss-Protection Date Access-Control-Request-Method Access-Control-Allow-Origin @@ -409,3 +409,4 @@ def teardown end CODE end + diff --git a/templates/lurker_app.rb b/templates/lurker_app.rb index e59d382..0f025d0 100644 --- a/templates/lurker_app.rb +++ b/templates/lurker_app.rb @@ -69,3 +69,4 @@ web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb CODE end +