lurker 0.6.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/.hound.yml +4 -78
  3. data/.jshintrc +33 -0
  4. data/.rspec +1 -2
  5. data/.rubocop.yml +0 -1
  6. data/.travis.yml +30 -19
  7. data/Gemfile +0 -33
  8. data/README.md +32 -53
  9. data/Rakefile +3 -3
  10. data/cucumber.yml +1 -2
  11. data/features/atom_persistent_within_the_same_type.feature +4 -4
  12. data/features/controller_nested_schema_scaffolding.feature +7 -10
  13. data/features/controller_schema_scaffolding.feature +1 -3
  14. data/features/dereferencing_through_inlining.feature +1 -3
  15. data/features/html_generation.feature +26 -4
  16. data/features/minitest.feature +3 -8
  17. data/features/multidomain_support.feature +6 -10
  18. data/features/multitype_request_support.feature +1 -3
  19. data/features/partials.feature +3 -8
  20. data/features/request_nested_schema_scaffolding.feature +0 -2
  21. data/features/request_schema_scaffolding.feature +0 -2
  22. data/features/schema_suffixes.feature +2 -18
  23. data/features/schema_updating_within_test_suite.feature +2 -6
  24. data/features/step_definitions/additional_cli_steps.rb +16 -12
  25. data/features/support/env.rb +50 -10
  26. data/features/test_endpoint.feature +2 -9
  27. data/gemfiles/rails_4.gemfile +14 -0
  28. data/gemfiles/rails_5.gemfile +10 -0
  29. data/gemfiles/rails_6.gemfile +10 -0
  30. data/lib/lurker.rb +9 -2
  31. data/lib/lurker/cli.rb +148 -128
  32. data/lib/lurker/endpoint.rb +11 -7
  33. data/lib/lurker/form_builder.rb +22 -31
  34. data/lib/lurker/json/concerns/validatable.rb +5 -1
  35. data/lib/lurker/json/parser.rb +1 -1
  36. data/lib/lurker/json/schema.rb +19 -6
  37. data/lib/lurker/json/{writter.rb → writer.rb} +2 -2
  38. data/lib/lurker/presenters/base_presenter.rb +10 -34
  39. data/lib/lurker/presenters/endpoint_presenter.rb +19 -8
  40. data/lib/lurker/presenters/schema_presenter.rb +6 -5
  41. data/lib/lurker/presenters/service_presenter.rb +41 -7
  42. data/lib/lurker/rendering_controller.rb +14 -7
  43. data/lib/lurker/service.rb +27 -11
  44. data/lib/lurker/spec_helper/rspec.rb +0 -4
  45. data/lib/lurker/spy.rb +3 -1
  46. data/lib/lurker/templates/documentation.md.tt +1 -0
  47. data/lib/lurker/templates/javascripts/lurker.js +133 -91
  48. data/lib/lurker/templates/layouts/_sidemenu.html.erb +2 -2
  49. data/lib/lurker/templates/layouts/application.html.erb +54 -57
  50. data/lib/lurker/templates/layouts/print.html.erb +31 -0
  51. data/lib/lurker/templates/lurker/rendering/_endpoint.html.erb +37 -0
  52. data/lib/lurker/templates/lurker/rendering/_param_form_element.html.erb +1 -1
  53. data/lib/lurker/templates/lurker/rendering/_service.html.erb +7 -0
  54. data/lib/lurker/templates/lurker/rendering/_submit_form.html.erb +77 -73
  55. data/lib/lurker/templates/lurker/rendering/all.html.erb +5 -0
  56. data/lib/lurker/templates/lurker/rendering/index.html.erb +1 -10
  57. data/lib/lurker/templates/lurker/rendering/show.html.erb +1 -37
  58. data/lib/lurker/templates/public/application.css +6 -2
  59. data/lib/lurker/templates/public/application.js +13 -13
  60. data/lib/lurker/templates/stylesheets/application.scss +3 -0
  61. data/lib/lurker/version.rb +1 -1
  62. data/lurker.gemspec +31 -33
  63. data/spec/spec_helper.rb +0 -1
  64. data/tasks/build.rake +12 -8
  65. data/tasks/generate.rake +44 -17
  66. data/templates/Dockerfile +26 -0
  67. data/templates/generate_stuff.rb +59 -26
  68. data/templates/lurker_app.rb +27 -48
  69. data/templates/rails4_ruby26_thread_error_fix.rb +20 -0
  70. metadata +149 -106
  71. checksums.yaml.gz.sig +0 -2
  72. data.tar.gz.sig +0 -3
  73. data/Appraisals +0 -20
  74. data/gemfiles/rails_32.gemfile +0 -27
  75. data/gemfiles/rails_40.gemfile +0 -27
  76. data/gemfiles/rails_41.gemfile +0 -27
  77. data/gemfiles/rails_42.gemfile +0 -27
  78. data/lib/lurker/templates/lurker/rendering/_param_form_legend.html.erb +0 -1
  79. data/lib/lurker/templates/meta_service.md.erb +0 -20
  80. data/lib/lurker/validation_error.rb +0 -4
  81. data/templates/rails32_http_patch_support.rb +0 -125
  82. metadata.gz.sig +0 -0
@@ -5,8 +5,6 @@ Feature: controller nested schema scaffolding
5
5
  Scenario: scaffold a json schema for a "repos/index" in a nested controller spec
6
6
  Given a file named "spec/controllers/api/v1/repos_controller_spec.rb" with:
7
7
  """ruby
8
- require "spec_helper"
9
-
10
8
  describe Api::V1::ReposController, :lurker do
11
9
  render_views
12
10
 
@@ -18,7 +16,9 @@ Feature: controller nested schema scaffolding
18
16
  end
19
17
 
20
18
  it "lists all the repos of the user" do
21
- get :index, user_id: user.id, limit: 1, format: 'json'
19
+ # rails 4 doesn't stringify values and schema has integers
20
+ # rails >= 5 have limit as string & proper query_params extension
21
+ get :index, params: { user_id: user.id, limit: 1, format: 'json' }
22
22
  expect(response).to be_success
23
23
  expect(JSON.parse(response.body).size).to eq 1
24
24
  end
@@ -28,7 +28,7 @@ Feature: controller nested schema scaffolding
28
28
  When I run `bin/rspec spec/controllers/api/v1/repos_controller_spec.rb`
29
29
  Then the example should pass
30
30
  Then a file named "lurker/api/v1/users/__user_id/repos-GET.json.yml" should exist
31
- Then the file "lurker/api/v1/users/__user_id/repos-GET.json.yml" should contain exactly:
31
+ Then the file "lurker/api/v1/users/__user_id/repos-GET.json.yml" should contain:
32
32
  """yml
33
33
  ---
34
34
  description: repo listing
@@ -40,9 +40,9 @@ Feature: controller nested schema scaffolding
40
40
  required: []
41
41
  properties:
42
42
  limit:
43
- description: ''
44
- type: integer
45
- example: 1
43
+ """
44
+ Then the file "lurker/api/v1/users/__user_id/repos-GET.json.yml" should contain:
45
+ """yml
46
46
  responseCodes:
47
47
  - status: 200
48
48
  successful: true
@@ -74,8 +74,5 @@ Feature: controller nested schema scaffolding
74
74
  controller: api/v1/repos
75
75
  action: index
76
76
  user_id: '1'
77
- query_params:
78
- limit: 1
79
-
80
77
  """
81
78
 
@@ -7,8 +7,6 @@ Feature: controller schema scaffolding
7
7
  Scenario: scaffold a json schema for a "users/show" in controller spec
8
8
  Given a file named "spec/controllers/api/v1/users_controller_spec.rb" with:
9
9
  """ruby
10
- require "spec_helper"
11
-
12
10
  describe Api::V1::UsersController, :lurker do
13
11
  render_views
14
12
 
@@ -17,7 +15,7 @@ Feature: controller schema scaffolding
17
15
  end
18
16
 
19
17
  it "shows user" do
20
- get :show, id: user.id, format: 'json'
18
+ get :show, params: { id: user.id, format: 'json' }
21
19
  expect(response).to be_success
22
20
  end
23
21
  end
@@ -55,8 +55,6 @@ Feature: $ref defererencing through inlining
55
55
  """
56
56
  And a file named "spec/controllers/api/v3/users_controller_spec.rb" with:
57
57
  """ruby
58
- require "spec_helper"
59
-
60
58
  describe Api::V3::UsersController, :lurker do
61
59
  render_views
62
60
 
@@ -65,7 +63,7 @@ Feature: $ref defererencing through inlining
65
63
  end
66
64
 
67
65
  it "updates a user surname as string" do
68
- patch :update, id: user.id, user: { surname: 'Marley' }
66
+ patch :update, params: { id: user.id, user: { surname: 'Marley' } }
69
67
  expect(response).to be_success
70
68
  end
71
69
  end
@@ -2,12 +2,24 @@ Feature: html generation
2
2
 
3
3
  Lurker generates pretty info pages based on schema information
4
4
  and form which allow you to test live api.
5
- When testing your api ensure that CSRF protection is handled properlya
5
+ When testing your api ensure that CSRF protection is handled properly
6
6
  with `protect_from_forgery :null_session`
7
7
 
8
8
  @javascript
9
9
  Scenario: json schema gets generated into html preview using "users/create"
10
10
  Given an empty directory named "public/lurker"
11
+ And a service file with:
12
+ """yml
13
+ ---
14
+ name: Lurker Demo Application
15
+ basePath: ''
16
+ description: ''
17
+ domains:
18
+ 'razum2um.me': 'https://lurker.razum2um.me'
19
+ consumes:
20
+ - application/x-www-form-urlencoded
21
+ - application/json
22
+ """
11
23
  And a file named "lurker/api/v1/users-POST.json.yml" with:
12
24
  """yml
13
25
  ---
@@ -48,8 +60,8 @@ Feature: html generation
48
60
  Converting lurker to html
49
61
  using lurker
50
62
 
51
- create public/lurker/index.html
52
- create public/lurker/api/v1/users-POST.html
63
+ public/lurker/index.html
64
+ public/lurker/api/v1/users-POST.html
53
65
  """
54
66
 
55
67
  When I go to "/lurker"
@@ -62,7 +74,7 @@ Feature: html generation
62
74
  And I fill in the submit form field "name" with "Jim"
63
75
  Then I should see:
64
76
  """
65
- curl -X POST -d "user%5Bname%5D=Jim"
77
+ curl -X POST -d 'user%5Bname%5D=Jim'
66
78
  """
67
79
 
68
80
  And I submit lurk form
@@ -74,3 +86,13 @@ Feature: html generation
74
86
 
75
87
  Then I should see JSON response with "can't be blank"
76
88
 
89
+ When I select "application/json" request media type
90
+ And I fill in the submit form field "name" with "Jim"
91
+ Then I should see:
92
+ """
93
+ curl -X POST -H 'Content-Type: application/json' -d '{"user":{"name":"Jim"}}'
94
+ """
95
+
96
+ And I submit lurk form
97
+
98
+ Then I should see JSON response with "Jim"
@@ -49,10 +49,8 @@ Feature: minitest
49
49
  description: ''
50
50
  responseParameters:
51
51
  description: ''
52
- type: object
53
- additionalProperties: false
54
- required: []
55
- properties: {}
52
+ type: boolean
53
+ example: true
56
54
  extensions:
57
55
  method: DELETE
58
56
  path_info: "/api/v1/users/1/repos/1.json"
@@ -72,9 +70,6 @@ Feature: minitest
72
70
  description: 'user updating'
73
71
  requestParameters:
74
72
  properties:
75
- id:
76
- type: integer
77
- example: 1
78
73
  user:
79
74
  type: object
80
75
  properties:
@@ -115,7 +110,7 @@ Feature: minitest
115
110
  assert_equal 1, User.count
116
111
 
117
112
  Lurker::Spy.on do
118
- patch "/api/v1/users/#{user.id}.json", user: { name: '' }
113
+ patch "/api/v1/users/#{user.id}.json", params: { user: { name: '' } }
119
114
  end
120
115
 
121
116
  assert_equal 200, status
@@ -22,8 +22,7 @@ Feature: mutidomain support
22
22
  basePath: ''
23
23
  description: ''
24
24
  domains:
25
- '[Sandbox] Heroku': 'http://lurker-app.herokuapp.com'
26
- '[Real] razum2um.me': 'http://lurker.razum2um.me'
25
+ 'razum2um.me': 'https://lurker.razum2um.me'
27
26
  name: Lurker Demo Application
28
27
  extensions: {}
29
28
  """
@@ -33,10 +32,7 @@ Feature: mutidomain support
33
32
  prefix: users management
34
33
  description: user deletion
35
34
  requestParameters:
36
- properties:
37
- id:
38
- type: integer
39
- example: 1
35
+ properties: {}
40
36
  responseCodes:
41
37
  - status: 200
42
38
  successful: true
@@ -58,14 +54,14 @@ Feature: mutidomain support
58
54
  Converting lurker to html
59
55
  using lurker
60
56
 
61
- create public/lurker/index.html
62
- create public/lurker/api/v1/users/__id-DELETE.html
57
+ public/lurker/index.html
58
+ public/lurker/api/v1/users/__id-DELETE.html
63
59
  """
64
60
 
65
61
  When I go to "/lurker/api/v1/users/__id-DELETE.html"
66
- When I select "[Sandbox] Heroku" hostname
62
+ When I select "razum2um.me" hostname
67
63
  Then I should see:
68
64
  """
69
- curl -X DELETE "http://lurker-app.herokuapp.com/api/v1/users/1"
65
+ curl -X DELETE 'https://lurker.razum2um.me/api/v1/users/1'
70
66
  """
71
67
 
@@ -60,8 +60,6 @@ Feature: multitype request support
60
60
  Scenario: json schema tests response parameters and update request parameters using "users/update"
61
61
  Given a file named "spec/controllers/api/v2/users_controller_spec.rb" with:
62
62
  """ruby
63
- require "spec_helper"
64
-
65
63
  describe Api::V2::UsersController, :lurker do
66
64
  render_views
67
65
 
@@ -70,7 +68,7 @@ Feature: multitype request support
70
68
  end
71
69
 
72
70
  it "updates a user surname as string" do
73
- patch :update, id: user.id, user: { surname: 'Marley' }
71
+ patch :update, params: { id: user.id, user: { surname: 'Marley' } }
74
72
  expect(response).to be_success
75
73
  end
76
74
  end
@@ -44,9 +44,6 @@ Feature: partials
44
44
  prefix: repos management
45
45
  requestParameters:
46
46
  properties:
47
- user_id:
48
- type: string
49
- example: 1
50
47
  repo:
51
48
  properties:
52
49
  name:
@@ -68,8 +65,6 @@ Feature: partials
68
65
 
69
66
  Given a file named "spec/requests/repo_creation_spec.rb" with:
70
67
  """ruby
71
- require "spec_helper"
72
-
73
68
  describe Api::V1::ReposController, :lurker do
74
69
  let!(:user) do
75
70
  User.where(name: 'razum2um').first_or_create!
@@ -77,7 +72,7 @@ Feature: partials
77
72
 
78
73
  it "creates a new repo" do
79
74
  expect {
80
- post "/api/v1/users/#{user.id}/repos.json", repo: { name: 'new-gem' }
75
+ post "/api/v1/users/#{user.id}/repos.json", params: { repo: { name: 'new-gem' } }
81
76
  expect(response).to be_success
82
77
  expect(JSON.parse(response.body)['user']).to eq JSON.parse(user.to_json)
83
78
  }.to change { Repo.count } .by(1)
@@ -94,7 +89,7 @@ Feature: partials
94
89
  Converting lurker to html
95
90
  using lurker
96
91
 
97
- create public/lurker/index.html
98
- create public/lurker/api/v1/users/__user_id/repos-POST.html
92
+ public/lurker/index.html
93
+ public/lurker/api/v1/users/__user_id/repos-POST.html
99
94
  """
100
95
 
@@ -5,8 +5,6 @@ Feature: request nested schema scaffolding
5
5
  Scenario: scaffold a json schema for a "repos/show" in a nested controller spec
6
6
  Given a file named "spec/requests/repos_spec.rb" with:
7
7
  """ruby
8
- require "spec_helper"
9
-
10
8
  describe Api::V1::ReposController, :lurker do
11
9
  let!(:user) do
12
10
  User.where(name: 'razum2um').first_or_create!.tap do |u|
@@ -7,8 +7,6 @@ Feature: request schema scaffolding
7
7
  Scenario: scaffold a json schema for a "users/index" in request spec
8
8
  Given a file named "spec/requests/users_spec.rb" with:
9
9
  """ruby
10
- require "spec_helper"
11
-
12
10
  describe Api::V1::UsersController, :lurker do
13
11
  let!(:user) do
14
12
  User.where(name: 'razum2um', surname: 'Marley').first_or_create!
@@ -17,12 +17,6 @@ Feature: schema suffixes
17
17
  description: 'repo updating'
18
18
  requestParameters:
19
19
  properties:
20
- id:
21
- type: string
22
- example: 1
23
- user_id:
24
- type: string
25
- example: razum2um
26
20
  repo:
27
21
  type: object
28
22
  properties:
@@ -56,8 +50,6 @@ Feature: schema suffixes
56
50
  """
57
51
  And a file named "spec/requests/updating_repos_spec.rb" with:
58
52
  """ruby
59
- require "spec_helper"
60
-
61
53
  describe Api::V1::ReposController, :lurker, type: :request do
62
54
 
63
55
  let(:user) do
@@ -70,7 +62,7 @@ Feature: schema suffixes
70
62
 
71
63
  it "updates a repo name" do
72
64
  expect {
73
- patch "/api/v1/users/#{user.name}/repos/#{repo.name}.json", repo: { name: 'updated-name' }
65
+ patch "/api/v1/users/#{user.name}/repos/#{repo.name}.json", params: { repo: { name: 'updated-name' } }
74
66
  expect(response).to be_success
75
67
  }.to change { repo.reload.name } .from('lurker').to('updated-name')
76
68
  end
@@ -88,12 +80,6 @@ Feature: schema suffixes
88
80
  description: 'failed repo updating'
89
81
  requestParameters:
90
82
  properties:
91
- id:
92
- type: string
93
- example: 1
94
- user_id:
95
- type: string
96
- example: razum2um
97
83
  repo:
98
84
  type: object
99
85
  properties:
@@ -127,8 +113,6 @@ Feature: schema suffixes
127
113
  """
128
114
  And a file named "spec/requests/failed_updating_repos_spec.rb" with:
129
115
  """ruby
130
- require "spec_helper"
131
-
132
116
  describe Api::V1::ReposController, type: :request do
133
117
 
134
118
  let(:user) do
@@ -141,7 +125,7 @@ Feature: schema suffixes
141
125
 
142
126
  it "fails to update a repo with a blank name", lurker: 'failed' do
143
127
  expect {
144
- patch "/api/v1/users/#{user.name}/repos/#{repo.name}.json", repo: { name: '' }
128
+ patch "/api/v1/users/#{user.name}/repos/#{repo.name}.json", params: { repo: { name: '' } }
145
129
  expect(response).not_to be_success
146
130
  }.not_to change { repo.reload.name }
147
131
  end
@@ -62,8 +62,6 @@ Feature: schema updating within test suite
62
62
  Scenario: json schema tests response parameters and request parameters and show errors from both using "users/update"
63
63
  Given a file named "spec/controllers/api/v2/users_controller_blank_spec.rb" with:
64
64
  """ruby
65
- require "spec_helper"
66
-
67
65
  describe Api::V2::UsersController, :lurker do
68
66
  render_views
69
67
 
@@ -72,7 +70,7 @@ Feature: schema updating within test suite
72
70
  end
73
71
 
74
72
  it "updates a user surname as string" do
75
- patch :update, id: user.id, user: { name: '', surname: 'Marley' }
73
+ patch :update, params: { id: user.id, user: { name: '', surname: 'Marley' } }
76
74
  expect(response).not_to be_success
77
75
  end
78
76
  end
@@ -93,8 +91,6 @@ Feature: schema updating within test suite
93
91
  Scenario: json schema tests response parameters and update request parameters using "users/update"
94
92
  Given a file named "spec/controllers/api/v2/users_controller_spec.rb" with:
95
93
  """ruby
96
- require "spec_helper"
97
-
98
94
  describe Api::V2::UsersController, :lurker do
99
95
  render_views
100
96
 
@@ -103,7 +99,7 @@ Feature: schema updating within test suite
103
99
  end
104
100
 
105
101
  it "updates a user surname as string" do
106
- patch :update, id: user.id, user: { surname: 'Marley' }
102
+ patch :update, params: { id: user.id, user: { surname: 'Marley' } }
107
103
  expect(response).to be_success
108
104
  end
109
105
  end
@@ -2,17 +2,14 @@ Given /^a checked file "([^"]*)" with:$/ do |file_name, file_content|
2
2
  write_file(file_name, file_content)
3
3
 
4
4
  @files ||= {}
5
- in_current_dir { @files[md5(file_name)] = checksum(file_name) }
6
- end
7
-
8
- Given /^an empty directory named "([^"]*)"$/ do |dir_name|
9
- in_current_dir { _rm_rf(dir_name) }
10
- create_dir(dir_name)
5
+ in_current_directory { @files[md5(file_name)] = checksum(file_name) }
11
6
  end
12
7
 
13
8
  Given /^a service file with:$/ do |file_content|
14
- in_current_dir do
15
- write_file("#{Lurker::DEFAULT_SERVICE_PATH}/#{Rails.application.class.parent_name}#{Lurker::Service::SUFFIX}", file_content)
9
+ in_current_directory do
10
+ rails_app_class = Rails.application.class
11
+ rails_app_name = rails_app_class.respond_to?(:module_parent_name) ? rails_app_class.module_parent_name : rails_app_class.parent_name
12
+ write_file("#{Lurker::DEFAULT_SERVICE_PATH}/#{rails_app_name}#{Lurker::Service::SUFFIX}", file_content)
16
13
  end
17
14
  end
18
15
 
@@ -30,7 +27,14 @@ When /^I select "([^"]*)" hostname$/ do |host|
30
27
  end
31
28
  # FIXME: see multidomain feature - cannot select node in phantomjs
32
29
  page.execute_script("window.submitForm.setState({host: jQuery('#hostname').val()});")
33
- page.execute_script("window.submitForm.afterSetPartialState()")
30
+ end
31
+
32
+ When /^I select "([^"]*)" request media type$/ do |type|
33
+ within(:xpath, "//*[@id='requestMediaType']") do
34
+ select(type)
35
+ end
36
+ # FIXME: cannot select node in phantomjs
37
+ page.execute_script("window.submitForm.setState({requestMediaType: jQuery('#requestMediaType').val()});")
34
38
  end
35
39
 
36
40
  When(/^I fill in the submit form field "([^"]*)" with "([^"]*)"$/) do |field, name|
@@ -76,7 +80,7 @@ end
76
80
  Then /^the output should contain (failures|these lines):$/ do |_, lines|
77
81
  out = all_output.dup
78
82
  lines.split(/\n/).map(&:strip).each do |line|
79
- next if line.blank?
83
+ next if line.strip!.blank?
80
84
  expect(out).to match /#{Regexp.escape(line)}/
81
85
  out.gsub!(/.*?#{Regexp.escape(line)}/m, '')
82
86
  end
@@ -98,13 +102,13 @@ Then(/^I should see JSON response with "([^"]*)"$/) do |name|
98
102
  end
99
103
 
100
104
  Then /(?:a|the) checked file "([^"]*)" should not change$/ do |file_name|
101
- in_current_dir do
105
+ in_current_directory do
102
106
  expect(@files.try(:[], md5(file_name))).to eq checksum(file_name)
103
107
  end
104
108
  end
105
109
 
106
110
  Then /(?:a|the) checked file "([^"]*)" should change$/ do |file_name|
107
- in_current_dir do
111
+ in_current_directory do
108
112
  expect(@files.try(:[], md5(file_name))).not_to eq checksum(file_name)
109
113
  end
110
114
  end