learn-web 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -0
- data/Guardfile +42 -0
- data/Rakefile +5 -0
- data/learn-web.gemspec +3 -0
- data/lib/learn_web/client.rb +2 -0
- data/lib/learn_web/client/ssh_keys.rb +22 -0
- data/lib/learn_web/client/ssh_keys/add.rb +35 -0
- data/lib/learn_web/version.rb +1 -1
- data/spec/learn_web/client_spec.rb +73 -0
- data/spec/spec_helper.rb +13 -0
- metadata +54 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c8a4ccdaa67f5a0a8215220e4fb82eb336975eb5667898ec519de72cd59fe67
|
4
|
+
data.tar.gz: 9e993f17ca4d284b6edb9fd9b26508acf196f8617bf534ceec58500c41f1ec1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a8242ed8d224d33e036fd4536ddd856af795f179431df531b813789b9b6c6761eff5049047b3c21761400de01c24390edaa9a3c9aeb516e5e7040d236726a82
|
7
|
+
data.tar.gz: b6339d5b79ed045569d9b4a13ef6a2b51791f1f900224a0b4c012d7394f8fe9a9a1bee7dcf7506af811c1a37471b861dbe45568149cc1099a35aaff4b3c4c040
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Guardfile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# RSpec files
|
6
|
+
rspec = dsl.rspec
|
7
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
9
|
+
watch(rspec.spec_files)
|
10
|
+
|
11
|
+
# Ruby files
|
12
|
+
ruby = dsl.ruby
|
13
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
14
|
+
|
15
|
+
# Rails files
|
16
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
17
|
+
dsl.watch_spec_files_for(rails.app_files)
|
18
|
+
dsl.watch_spec_files_for(rails.views)
|
19
|
+
|
20
|
+
watch(rails.controllers) do |m|
|
21
|
+
[
|
22
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
23
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
24
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Rails config changes
|
29
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
30
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
31
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
32
|
+
|
33
|
+
# Capybara features specs
|
34
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
35
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
36
|
+
|
37
|
+
# Turnip features and steps
|
38
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
39
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
40
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
41
|
+
end
|
42
|
+
end
|
data/Rakefile
CHANGED
data/learn-web.gemspec
CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.7"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "pry", "~> 0.11.3"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.8.0"
|
24
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7.0"
|
22
25
|
|
23
26
|
spec.add_runtime_dependency "faraday", "~> 0.9"
|
24
27
|
spec.add_runtime_dependency "oj", "~> 2.9"
|
data/lib/learn_web/client.rb
CHANGED
@@ -7,6 +7,7 @@ require 'learn_web/client/validate_repo'
|
|
7
7
|
require 'learn_web/client/fork'
|
8
8
|
require 'learn_web/client/environment'
|
9
9
|
require 'learn_web/client/event'
|
10
|
+
require 'learn_web/client/ssh_keys'
|
10
11
|
|
11
12
|
module LearnWeb
|
12
13
|
class Client
|
@@ -24,6 +25,7 @@ module LearnWeb
|
|
24
25
|
include LearnWeb::Client::User
|
25
26
|
include LearnWeb::Client::Environment
|
26
27
|
include LearnWeb::Client::Event
|
28
|
+
include LearnWeb::Client::SshKeys
|
27
29
|
|
28
30
|
def initialize(token:, silent_output: false)
|
29
31
|
@token = token
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'learn_web/client/ssh_keys/add'
|
2
|
+
|
3
|
+
module LearnWeb
|
4
|
+
class Client
|
5
|
+
module SshKeys
|
6
|
+
def add_ssh_key_endpoint
|
7
|
+
"#{API_ROOT}/ssh_keys"
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_ssh_key(key:, key_title: nil, client: nil)
|
11
|
+
response = post(
|
12
|
+
add_ssh_key_endpoint,
|
13
|
+
headers: { 'Authorization' => "Bearer #{token}" },
|
14
|
+
params: { 'key' => key, key_title: key_title }.compact,
|
15
|
+
client: client
|
16
|
+
)
|
17
|
+
|
18
|
+
LearnWeb::Client::SshKeys::Add.new(response).parse!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module LearnWeb
|
2
|
+
class Client
|
3
|
+
module SshKeys
|
4
|
+
class Add
|
5
|
+
attr_reader :response
|
6
|
+
attr_accessor :data
|
7
|
+
|
8
|
+
include LearnWeb::AttributePopulatable
|
9
|
+
|
10
|
+
def initialize(response)
|
11
|
+
@response = response
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse!
|
15
|
+
if response.status == 200
|
16
|
+
self.data = Oj.load(response.body, symbol_keys: true)
|
17
|
+
|
18
|
+
populate_attributes!
|
19
|
+
self
|
20
|
+
else
|
21
|
+
case response.status
|
22
|
+
when 304
|
23
|
+
puts "This key is already in use."
|
24
|
+
when 422
|
25
|
+
puts "Something went wrong. Please try again."
|
26
|
+
else
|
27
|
+
puts "Something went wrong. Please try again."
|
28
|
+
end
|
29
|
+
:error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/learn_web/version.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
RSpec.describe LearnWeb::Client do
|
4
|
+
context "Constants" do
|
5
|
+
it "sets the LEARN_URL to learn.co" do
|
6
|
+
expect(LearnWeb::Client::LEARN_URL).to eq("https://learn.co")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "sets the API_ROOT to the root" do
|
10
|
+
expect(LearnWeb::Client::API_ROOT).to eq("/api/v1")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "Adding an ssh key" do
|
15
|
+
let(:headers) { {} }
|
16
|
+
let(:params) { {} }
|
17
|
+
let(:req_double) { double("request double", headers: headers, params: params) } # Faraday's weird api
|
18
|
+
let(:web_client) { double }
|
19
|
+
let(:client) { LearnWeb::Client.new(token: "mytoken") }
|
20
|
+
|
21
|
+
before do
|
22
|
+
allow(req_double).to receive(:url).with("/api/v1/ssh_keys")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "correctly makes the request" do
|
26
|
+
expect(web_client).to receive(:post)
|
27
|
+
.and_yield(req_double)
|
28
|
+
.and_return(double(status: 200, body: {message: "Success"}.to_json))
|
29
|
+
client.add_ssh_key(key: "a valid ssh key", key_title: "LearnWeb Test Suite", client: web_client)
|
30
|
+
|
31
|
+
expect(headers).to eq({"Authorization"=>"Bearer mytoken"})
|
32
|
+
expect(params).to eq({"key"=>"a valid ssh key", :key_title=>"LearnWeb Test Suite"})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does not send a key title if not provided" do
|
36
|
+
expect(web_client).to receive(:post)
|
37
|
+
.and_yield(req_double)
|
38
|
+
.and_return(double(status: 200, body: {message: "Success"}.to_json))
|
39
|
+
|
40
|
+
client.add_ssh_key(key: "a valid ssh key", client: web_client)
|
41
|
+
|
42
|
+
expect(headers).to eq({"Authorization"=>"Bearer mytoken"})
|
43
|
+
expect(params).to eq({"key"=>"a valid ssh key"})
|
44
|
+
end
|
45
|
+
|
46
|
+
it "prints info on 304" do
|
47
|
+
expect(web_client).to receive(:post)
|
48
|
+
.and_yield(req_double)
|
49
|
+
.and_return(double(status: 304, body: {message: "womp"}.to_json))
|
50
|
+
expect do
|
51
|
+
client.add_ssh_key(key: "a valid ssh key", client: web_client)
|
52
|
+
end.to output("This key is already in use.\n").to_stdout
|
53
|
+
|
54
|
+
end
|
55
|
+
it "prints info on 422" do
|
56
|
+
expect(web_client).to receive(:post)
|
57
|
+
.and_yield(req_double)
|
58
|
+
.and_return(double(status: 422, body: {message: "womp"}.to_json))
|
59
|
+
expect do
|
60
|
+
client.add_ssh_key(key: "a valid ssh key", client: web_client)
|
61
|
+
end.to output("Something went wrong. Please try again.\n").to_stdout
|
62
|
+
end
|
63
|
+
|
64
|
+
it "prints info on anything else" do
|
65
|
+
expect(web_client).to receive(:post)
|
66
|
+
.and_yield(req_double)
|
67
|
+
.and_return(double(status: 418, body: {message: "womp"}.to_json))
|
68
|
+
expect do
|
69
|
+
client.add_ssh_key(key: "a valid ssh key", client: web_client)
|
70
|
+
end.to output("Something went wrong. Please try again.\n").to_stdout
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$: << '.'
|
2
|
+
require 'lib/learn_web'
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.verify_partial_doubles = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: learn-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flatiron School
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.11.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.11.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.8.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.8.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.7.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.7.0
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: faraday
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +116,9 @@ extensions: []
|
|
74
116
|
extra_rdoc_files: []
|
75
117
|
files:
|
76
118
|
- ".gitignore"
|
119
|
+
- ".rspec"
|
77
120
|
- Gemfile
|
121
|
+
- Guardfile
|
78
122
|
- LICENSE.txt
|
79
123
|
- README.md
|
80
124
|
- Rakefile
|
@@ -97,12 +141,16 @@ files:
|
|
97
141
|
- lib/learn_web/client/pull_request.rb
|
98
142
|
- lib/learn_web/client/pull_request/response.rb
|
99
143
|
- lib/learn_web/client/request.rb
|
144
|
+
- lib/learn_web/client/ssh_keys.rb
|
145
|
+
- lib/learn_web/client/ssh_keys/add.rb
|
100
146
|
- lib/learn_web/client/user.rb
|
101
147
|
- lib/learn_web/client/user/me.rb
|
102
148
|
- lib/learn_web/client/validate_repo.rb
|
103
149
|
- lib/learn_web/client/validate_repo/slug.rb
|
104
150
|
- lib/learn_web/response_parsable.rb
|
105
151
|
- lib/learn_web/version.rb
|
152
|
+
- spec/learn_web/client_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
106
154
|
homepage: https://learn.co
|
107
155
|
licenses:
|
108
156
|
- MIT
|
@@ -123,8 +171,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
171
|
version: '0'
|
124
172
|
requirements: []
|
125
173
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.6
|
174
|
+
rubygems_version: 2.7.6
|
127
175
|
signing_key:
|
128
176
|
specification_version: 4
|
129
177
|
summary: An interface to Learn.co
|
130
|
-
test_files:
|
178
|
+
test_files:
|
179
|
+
- spec/learn_web/client_spec.rb
|
180
|
+
- spec/spec_helper.rb
|