codeunion 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Resolve the pathname for this executable
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # Add the gem's "lib" directory to library path
9
+ $LOAD_PATH.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ require "codeunion/command/search"
12
+ require "optparse"
13
+
14
+ options = {}
15
+ parser = OptionParser.new do |opts|
16
+ opts.instance_exec do
17
+ self.banner = "Usage: codeunion projects <terms>"
18
+
19
+ on_tail("-h", "--help", "Print this help message") do
20
+ puts self
21
+ exit
22
+ end
23
+ end
24
+ end
25
+
26
+ if ARGV.empty?
27
+ puts parser
28
+ exit
29
+ else
30
+ parser.parse!(ARGV)
31
+ end
32
+
33
+ options[:category] = "projects"
34
+ options[:query] = ARGV
35
+
36
+ result = CodeUnion::Command::Search.new(options).run
37
+ puts result if result
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Resolve the pathname for this executable
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # Add the gem's "lib" directory to library path
9
+ $LOAD_PATH.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ require "codeunion/command/search"
12
+ require "optparse"
13
+
14
+ options = {}
15
+ parser = OptionParser.new do |opts|
16
+ opts.instance_exec do
17
+ self.banner = "Usage: codeunion search [options] <terms>"
18
+
19
+ separator ""
20
+ separator "Options:"
21
+ on("-c", "--category CATEGORY", "Display config variable NAME") do |name|
22
+ options[:category] = name
23
+ end
24
+
25
+ on_tail("-h", "--help", "Print this help message") do
26
+ puts self
27
+ exit
28
+ end
29
+ end
30
+ end
31
+
32
+ if ARGV.empty?
33
+ puts parser
34
+ exit
35
+ else
36
+ parser.parse!(ARGV)
37
+ end
38
+
39
+ options[:query] = ARGV
40
+
41
+ result = CodeUnion::Command::Search.new(options).run
42
+ puts result if result
@@ -0,0 +1,4 @@
1
+ test_dir = File.dirname(File.expand_path(__FILE__))
2
+ Dir["#{test_dir}/features/**/*_test.rb"].each do |f|
3
+ require f
4
+ end
@@ -0,0 +1,27 @@
1
+ require "minitest/autorun"
2
+
3
+ # Verify setting, getting, and unsetting config values end to end.
4
+ class TestCodunionConfigFeature < MiniTest::Test
5
+ def config(option)
6
+ `libexec/codeunion-config #{option}`
7
+ end
8
+
9
+ def test_setting_a_value
10
+ config("unset test.value")
11
+ config("set test.value 'new_value'")
12
+ actual = config("get test.value").strip()
13
+ assert_equal "new_value", actual
14
+ config("unset test.value")
15
+ end
16
+
17
+ def test_unsetting_a_value
18
+ config("set test.value 'new_value'")
19
+ config("set test.other 'brother'")
20
+ config("unset test.value")
21
+ actual = config("get test.value").strip()
22
+ assert_equal "", actual
23
+
24
+ actual = config("get test.other").strip()
25
+ assert_equal "brother", actual
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module Fixtures
2
+ module CodeUnionAPI
3
+ def self.search_results
4
+ { "REST API" =>
5
+ [{
6
+ "name" => "linkedout-example",
7
+ "description" => "Example code for codeunion/linkedout: a one-page resume management system.",
8
+ "private" => true,
9
+ "url" => "https://github.com/codeunion/linkedout-example",
10
+ "category" => "examples",
11
+ "tags" => ["ruby", "sinatra", "javascript", "jquery", "ajax", "request-routing", "json", "dom-manipulation"],
12
+ "access" => ["students", "staff"],
13
+ "license" => true,
14
+ "has_wiki" => false,
15
+ "notes" => "",
16
+ "excerpt" => "<match>api</match>-post]:http://api.jquery.com/jquery.post/\n[jquery-<match>api</match>-append]:http://api.jquery.com/append/\n[jquery-<match>api</match>-serialize]:http://api.jquery.com"
17
+ }, {
18
+ "name" => "overheard-server",
19
+ "description" => "Example project for a web app that stores and shares hilarious, out of context quotess and quips.",
20
+ "private" => false,
21
+ "url" => "https://github.com/codeunion/overheard-server",
22
+ "category" => "examples",
23
+ "tags" => ["ruby", "sinatra", "datamapper", "sqlite"],
24
+ "access" => ["public", "students", "staff"],
25
+ "license" => true,
26
+ "has_wiki" => false,
27
+ "notes" => "Unclear purpose. Is it an example project or a tool?",
28
+ "excerpt" => "<match>REST</match> <match>API</match> to add and list Overheards\n\nFor a list of planned and implemented features"
29
+ }]
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ test_dir = File.dirname(File.expand_path(__FILE__))
2
+
3
+ Dir["#{test_dir}/unit/**/*_test.rb"].each do |f|
4
+ require f
5
+ end
@@ -0,0 +1,39 @@
1
+ lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "..", "lib")
2
+ $LOAD_PATH.unshift(lib_dir)
3
+
4
+ require "securerandom"
5
+ require "minitest/autorun"
6
+ require "codeunion/config"
7
+
8
+ module CodeUnion
9
+ # Set, Get, and Unset config variables from a real config file.
10
+ class ConfigTest < MiniTest::Test
11
+ def fixture(name)
12
+ File.join(File.dirname(File.expand_path(__FILE__)), "fixtures", name)
13
+ end
14
+
15
+ def test_getting_a_value_from_config
16
+ config = Config.load(fixture("sample_config"))
17
+ assert_equal("baz", config.get("foo.bear"))
18
+ end
19
+
20
+ def test_setting_a_value_in_a_config
21
+ config = Config.load(fixture("sample_config"))
22
+ config.set("foo.bear", "banana")
23
+ assert_equal("banana", config.get("foo.bear"))
24
+ end
25
+
26
+ def test_writing_a_config_file
27
+ File.delete(fixture("mutable_config")) if File.exist?(fixture("mutable_config"))
28
+ config = Config.load(fixture("mutable_config"))
29
+ value = SecureRandom.hex(6)
30
+ key = SecureRandom.hex(6)
31
+ config.set(key, value)
32
+ config.write
33
+
34
+ reloaded_config = Config.load(fixture("mutable_config"))
35
+
36
+ assert_equal(value, reloaded_config.get(key))
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,119 @@
1
+ lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "..", "lib")
2
+ $LOAD_PATH.unshift(lib_dir)
3
+
4
+ require "minitest/autorun"
5
+ require "codeunion/feedback_request"
6
+
7
+ module CodeUnion
8
+ # Fake version of the GithubAPI that acts as a spy
9
+ class FakeGithubAPI
10
+ @requests = []
11
+ class << self
12
+ attr_reader :requests
13
+ end
14
+
15
+ def initialize(access_token)
16
+ @access_token = access_token
17
+ end
18
+
19
+ def create_issue(title, content, repository)
20
+ self.class.requests.push({ :type => :create_issue,
21
+ :title => title,
22
+ :content => content,
23
+ :repository => repository,
24
+ :token => @access_token })
25
+ end
26
+
27
+ def self.last_request
28
+ @requests.last
29
+ end
30
+ end
31
+
32
+ # Ensures FeedbackRequest's interacts well with the GithubAPI
33
+ class FeedbackRequestTest < MiniTest::Test
34
+ DEFAULT_ARTIFACT = "http://example.com"
35
+ def send_request(artifact_to_review, repository = "", access_token = "fake_token")
36
+ request = FeedbackRequest.new(artifact_to_review, access_token, repository, { :github_api => FakeGithubAPI })
37
+ request.send!
38
+ request
39
+ end
40
+
41
+ def assert_valid_artifact(artifact, msg = "#{artifact} is an invalid artifact")
42
+ request = send_request(artifact)
43
+ assert request.valid?, msg
44
+ end
45
+
46
+ def test_web_urls_are_valid_artifacts
47
+ assert_valid_artifact("http://foo.com")
48
+ assert_valid_artifact("https://foo.com")
49
+ end
50
+
51
+ def refute_valid_artifact(artifact, msg = "#{artifact} is a valid artifact")
52
+ request = send_request(artifact)
53
+ refute request.valid?, msg
54
+ end
55
+
56
+ def test_non_urls_are_not_valid_artifacts
57
+ refute_valid_artifact("ftp://foo.com")
58
+ refute_valid_artifact("foo.com")
59
+ refute_valid_artifact("")
60
+ end
61
+
62
+ def test_sending_a_request_for_feedback
63
+ artifact_to_review = DEFAULT_ARTIFACT
64
+ access_token = "fake-token"
65
+ repository = "codeunion/web-fundamentals"
66
+
67
+ send_request(artifact_to_review, repository, access_token)
68
+
69
+ assert(FakeGithubAPI.last_request[:content].include?(artifact_to_review))
70
+ assert_equal(:create_issue, FakeGithubAPI.last_request[:type])
71
+ assert_equal(access_token, FakeGithubAPI.last_request[:token])
72
+ assert_equal(repository, FakeGithubAPI.last_request[:repository])
73
+ assert_equal(FeedbackRequest::ISSUE_TITLE, FakeGithubAPI.last_request[:title])
74
+ end
75
+
76
+ def assert_repository_becomes(expected_repository, input_value)
77
+ send_request(DEFAULT_ARTIFACT, input_value)
78
+
79
+ assert_equal(expected_repository, FakeGithubAPI.last_request[:repository])
80
+ end
81
+
82
+ def test_repository_prepends_default_owner
83
+ assert_repository_becomes("codeunion/web-fundamentals", "web-fundamentals")
84
+ end
85
+
86
+ def test_repository_may_include_non_codeunion_owner
87
+ assert_repository_becomes("zspencer/web-fundamentals", "zspencer/web-fundamentals")
88
+ end
89
+
90
+ def test_repository_removes_preceding_forward_slash
91
+ assert_repository_becomes("zspencer/web-fundamentals", "/zspencer/web-fundamentals")
92
+ end
93
+
94
+ def test_repository_can_be_github_web_url
95
+ repository = "codeunion/web-fundamentals"
96
+ assert_repository_becomes(repository, "https://github.com/#{repository}")
97
+ end
98
+
99
+ def test_repository_can_be_github_web_url_with_dot_git
100
+ repository = "codeunion/web-fundamentals"
101
+ assert_repository_becomes(repository, "https://github.com/#{repository}.git")
102
+ end
103
+
104
+ def test_repository_can_be_github_git_url
105
+ repository = "codeunion/web-fundamentals"
106
+ assert_repository_becomes(repository, "git://git@github.com:#{repository}.git")
107
+ end
108
+
109
+ def test_repository_can_be_a_github_git_url_without_the_dot_git
110
+ repository = "codeunion/web-fundamentals"
111
+ assert_repository_becomes(repository, "git://git@github.com:#{repository}")
112
+ end
113
+
114
+ def test_repository_can_be_a_github_git_url_without_the_protocol
115
+ repository = "codeunion/web-fundamentals"
116
+ assert_repository_becomes(repository, "git@github.com:#{repository}.git")
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ foo:
3
+ bear: baz
@@ -0,0 +1,59 @@
1
+ lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "..", "lib")
2
+ test_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "..", "test")
3
+ $LOAD_PATH.unshift(lib_dir)
4
+ $LOAD_PATH.unshift(test_dir)
5
+
6
+ require "minitest/autorun"
7
+ require "fixtures/codeunion_api_search"
8
+ require "codeunion/search"
9
+
10
+ module CodeUnion
11
+ class Search
12
+ # A Fake version of the codeunion API for testing purposes
13
+ class FakeCodeunionAPI
14
+ def search(options)
15
+ Fixtures::CodeUnionAPI.search_results()[options[:query]]
16
+ end
17
+ end
18
+
19
+ # Test the Search::ResultPresenter
20
+ class ResultPresenterTest < MiniTest::Test
21
+ include CodeUnion::Helpers::Text
22
+ def results
23
+ FakeCodeunionAPI.new.search({ :query => "REST API" })
24
+ end
25
+
26
+ def parse(result)
27
+ # Get rid of line breaks and padding so we're not testing
28
+ # indentation.
29
+ ResultPresenter.new(result).to_s.split("\n").map(&:strip).join(" ")
30
+ end
31
+
32
+ def assert_highlights(term, color, result)
33
+ Rainbow.enabled = true
34
+ assert(parse(result).include?(Rainbow(term).color(color)),
35
+ "#{term} was not highlighted #{color} in #{parse(result)}")
36
+ Rainbow.enabled = false
37
+ end
38
+
39
+ def assert_content(content, result)
40
+ assert(parse(result).include?(content), "#{parse(result)} did not include #{content}")
41
+ end
42
+
43
+ def test_presenter_highlights
44
+ assert_highlights("Example", :red, results[0])
45
+ assert_highlights("linkedout-example", :blue, results[0])
46
+ assert_highlights("api", :blue, results[0])
47
+ assert_highlights(results[0]["url"], :green, results[0])
48
+ assert_highlights(results[0]["description"], :yellow, results[0])
49
+ assert_highlights("REST", :blue, results[1])
50
+ end
51
+
52
+ def test_presenter_content
53
+ expected_tags = "tags: ajax, dom-manipulation, javascript, jquery, json, request-routing, ruby, sinatra"
54
+ assert_content(expected_tags, results[0])
55
+ assert_content(results[0]["description"], results[0])
56
+ end
57
+ end
58
+ end
59
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeunion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Farmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.27'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: ptools
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,13 +80,82 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: addressable
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.3'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: multi_json
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.10'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.10'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rainbow
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
69
153
  description: The CodeUnion command-line tool helps students work through CodeUnion's
70
154
  curriculum.
71
155
  email:
72
156
  - jesse@codeunion.io
73
157
  executables:
74
158
  - codeunion
75
- - codeunion-config
76
159
  extensions: []
77
160
  extra_rdoc_files: []
78
161
  files:
@@ -80,18 +163,39 @@ files:
80
163
  - ".rubocop.yml"
81
164
  - Gemfile
82
165
  - LICENSE
166
+ - Makefile
83
167
  - README.md
84
168
  - Rakefile
85
169
  - bin/codeunion
86
- - bin/codeunion-config
87
170
  - codeunion.gemspec
88
171
  - lib/codeunion.rb
172
+ - lib/codeunion/api.rb
89
173
  - lib/codeunion/command.rb
90
174
  - lib/codeunion/command/base.rb
91
175
  - lib/codeunion/command/config.rb
176
+ - lib/codeunion/command/feedback.rb
92
177
  - lib/codeunion/command/main.rb
178
+ - lib/codeunion/command/search.rb
93
179
  - lib/codeunion/config.rb
180
+ - lib/codeunion/feedback_request.rb
181
+ - lib/codeunion/github_api.rb
182
+ - lib/codeunion/helpers/text.rb
183
+ - lib/codeunion/http_client.rb
184
+ - lib/codeunion/search.rb
94
185
  - lib/codeunion/version.rb
186
+ - libexec/codeunion-config
187
+ - libexec/codeunion-examples
188
+ - libexec/codeunion-feedback
189
+ - libexec/codeunion-projects
190
+ - libexec/codeunion-search
191
+ - test/features.rb
192
+ - test/features/config_test.rb
193
+ - test/fixtures/codeunion_api_search.rb
194
+ - test/unit.rb
195
+ - test/unit/config_test.rb
196
+ - test/unit/feedback_request_test.rb
197
+ - test/unit/fixtures/sample_config
198
+ - test/unit/search_test.rb
95
199
  homepage: http://github.com/codeunion/codeunion-client
96
200
  licenses:
97
201
  - MIT
@@ -116,4 +220,13 @@ rubygems_version: 2.2.2
116
220
  signing_key:
117
221
  specification_version: 4
118
222
  summary: The CodeUnion Command-Line Tool
119
- test_files: []
223
+ test_files:
224
+ - test/features.rb
225
+ - test/features/config_test.rb
226
+ - test/fixtures/codeunion_api_search.rb
227
+ - test/unit.rb
228
+ - test/unit/config_test.rb
229
+ - test/unit/feedback_request_test.rb
230
+ - test/unit/fixtures/sample_config
231
+ - test/unit/search_test.rb
232
+ has_rdoc: