radiant-ray-extension 3.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/LICENSE +19 -0
  2. data/README.markdown +30 -0
  3. data/Rakefile +26 -0
  4. data/bin/ray +5 -0
  5. data/doc/Extension.html +1189 -0
  6. data/doc/Ray.html +175 -0
  7. data/doc/Ray/CLI.html +585 -0
  8. data/doc/Ray/Cache.html +709 -0
  9. data/doc/Ray/Gem.html +760 -0
  10. data/doc/Ray/Git.html +278 -0
  11. data/doc/Ray/GitHub.html +553 -0
  12. data/doc/Ray/RubyGems.html +501 -0
  13. data/doc/Ray/Zip.html +300 -0
  14. data/doc/Search.html +433 -0
  15. data/doc/String.html +242 -0
  16. data/doc/_index.html +84 -0
  17. data/doc/class_list.html +47 -0
  18. data/doc/css/common.css +1 -0
  19. data/doc/css/full_list.css +55 -0
  20. data/doc/css/style.css +322 -0
  21. data/doc/file.LICENSE.html +85 -0
  22. data/doc/file.README.html +97 -0
  23. data/doc/file_list.html +46 -0
  24. data/doc/frames.html +13 -0
  25. data/doc/index.html +84 -0
  26. data/doc/js/app.js +205 -0
  27. data/doc/js/full_list.js +167 -0
  28. data/doc/js/jquery.js +16 -0
  29. data/doc/method_list.html +46 -0
  30. data/doc/top-level-namespace.html +105 -0
  31. data/lib/ray.rb +8 -0
  32. data/lib/ray/cli.rb +271 -0
  33. data/lib/ray/constants.rb +17 -0
  34. data/lib/ray/extension.rb +116 -0
  35. data/lib/ray/extension/gem.rb +96 -0
  36. data/lib/ray/extension/git.rb +30 -0
  37. data/lib/ray/extension/zip.rb +44 -0
  38. data/lib/ray/search.rb +62 -0
  39. data/lib/ray/search/cache.rb +61 -0
  40. data/lib/ray/search/github.rb +40 -0
  41. data/lib/ray/search/rubygems.rb +36 -0
  42. data/lib/ray/string.rb +18 -0
  43. data/ray.gemspec +31 -0
  44. data/spec/fixtures/Gemfile +4 -0
  45. data/spec/fixtures/cache_single.yml +8 -0
  46. data/spec/fixtures/cassettes/github_v2_api_no_matches.yml +38 -0
  47. data/spec/fixtures/cassettes/github_v2_api_search_no_matches.yml +38 -0
  48. data/spec/fixtures/cassettes/github_v2_api_search_reorder_children.yml +75 -0
  49. data/spec/fixtures/cassettes/github_v2_api_search_single.yml +74 -0
  50. data/spec/fixtures/cassettes/github_v3_api_owner_name.yml +75 -0
  51. data/spec/fixtures/cassettes/rubygems_v1_api_gem_info.yml +36 -0
  52. data/spec/fixtures/cassettes/rubygems_v1_api_no_matches.yml +34 -0
  53. data/spec/fixtures/cassettes/rubygems_v1_api_search_no_matches.yml +34 -0
  54. data/spec/fixtures/cassettes/rubygems_v1_api_search_reorder.yml +36 -0
  55. data/spec/fixtures/cassettes/rubygems_v1_api_search_reorder_children.yml +36 -0
  56. data/spec/fixtures/cassettes/rubygems_v1_api_search_single.yml +41 -0
  57. data/spec/fixtures/cassettes/zip_file.yml +101 -0
  58. data/spec/fixtures/dummy.zip +0 -0
  59. data/spec/fixtures/dummy/README +1 -0
  60. data/spec/fixtures/dummy/Rakefile +109 -0
  61. data/spec/fixtures/dummy/config/initializers/radiant_config.rb +3 -0
  62. data/spec/fixtures/dummy/config/locales/en.yml +3 -0
  63. data/spec/fixtures/dummy/config/routes.rb +5 -0
  64. data/spec/fixtures/dummy/dummy_extension.rb +21 -0
  65. data/spec/fixtures/dummy/lib/radiant-dummy-extension.rb +8 -0
  66. data/spec/fixtures/dummy/lib/tasks/dummy_extension_tasks.rake +47 -0
  67. data/spec/fixtures/dummy/public/stylesheets/extensions/dummy/dummy.css +0 -0
  68. data/spec/fixtures/dummy/radiant-dummy-extension.gemspec +29 -0
  69. data/spec/ray/cli_spec.rb +56 -0
  70. data/spec/ray/extension/gem_spec.rb +214 -0
  71. data/spec/ray/extension/git_spec.rb +216 -0
  72. data/spec/ray/extension/zip_spec.rb +239 -0
  73. data/spec/ray/search/cache_spec.rb +74 -0
  74. data/spec/ray/search/github_spec.rb +137 -0
  75. data/spec/ray/search/rubygems_spec.rb +127 -0
  76. data/spec/ray/string_spec.rb +30 -0
  77. data/spec/spec_helper.rb +27 -0
  78. metadata +205 -0
@@ -0,0 +1,239 @@
1
+ require "spec_helper"
2
+ require "ray/extension/zip"
3
+
4
+ module Extension
5
+ def run_task task, options = {} ; "" ; end
6
+ end
7
+
8
+ describe Ray::Zip do
9
+
10
+ describe "install" do
11
+
12
+ before do
13
+ FileUtils.mkdir_p Ray::EXT_DIR
14
+ @extension = Ray::Zip.new({
15
+ :name => "dummy",
16
+ :uri => "https://github.com/johnmuhl/ray-dummy-extension/zipball/master"
17
+ })
18
+ end
19
+
20
+ after { cleanup }
21
+
22
+ it "must raise if the extension is already installed" do
23
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/dummy"
24
+ proc { @extension.install }.must_raise RuntimeError
25
+ end
26
+
27
+ it "must install the extension" do
28
+ VCR.use_cassette("zip_file") do
29
+ @extension.install
30
+ File.exist?("#{Ray::EXT_DIR}/dummy/dummy_extension.rb").must_equal true
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ describe "download" do
37
+
38
+ before do
39
+ FileUtils.mkdir_p Ray::TMP_DIR
40
+ end
41
+
42
+ after { cleanup }
43
+
44
+ it "must raise if the name is not given" do
45
+ proc {
46
+ Ray::Zip.new({ :uri => "x" }).download
47
+ }.must_raise RuntimeError
48
+ end
49
+
50
+ it "must raise if the uri is not given" do
51
+ proc {
52
+ Ray::Zip.new({ :name => "x" }).download
53
+ }.must_raise RuntimeError
54
+ end
55
+
56
+ it "must download the file" do
57
+ VCR.use_cassette("zip_file") do
58
+ Ray::Zip.new({
59
+ :name => "dummy",
60
+ :uri => "https://github.com/johnmuhl/ray-dummy-extension/zipball/master"
61
+ }).download
62
+ end
63
+ File.exist?("#{Ray::TMP_DIR}/master").must_equal true
64
+ end
65
+
66
+ end
67
+
68
+ describe "extract" do
69
+
70
+ before do
71
+ FileUtils.mkdir_p Ray::TMP_DIR
72
+ end
73
+
74
+ after { cleanup }
75
+
76
+ it "must raise if the file does not exist" do
77
+ proc {
78
+ Ray::Zip.new.extract
79
+ }.must_raise RuntimeError
80
+ end
81
+
82
+ it "must extract zip archives" do
83
+ FileUtils.cp "#{Dir.pwd}/spec/fixtures/dummy.zip", "#{Ray::TMP_DIR}/dummy.zip"
84
+ Ray::Zip.new.extract
85
+ File.exist?("#{Ray::TMP_DIR}/dummy/dummy_extension.rb").must_equal true
86
+ end
87
+
88
+ end
89
+
90
+ describe "disable" do
91
+
92
+ before do
93
+ FileUtils.mkdir_p Ray::EXT_DIR
94
+ FileUtils.mkdir_p Ray::TMP_DIR
95
+ @extension = Ray::Zip.new({ :name => "dummy" })
96
+ end
97
+
98
+ after { cleanup }
99
+
100
+ it "must raise if the extension is not installed" do
101
+ proc { @extension.disable }.must_raise RuntimeError
102
+ end
103
+
104
+ it "must disable the extension" do
105
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/dummy"
106
+ @extension.disable
107
+ File.exist?("#{Ray::EXT_DIR}/.disabled/dummy/dummy_extension.rb").must_equal true
108
+ end
109
+
110
+ end
111
+
112
+ describe "enable" do
113
+
114
+ before do
115
+ FileUtils.mkdir_p "#{Ray::EXT_DIR}/.disabled"
116
+ FileUtils.mkdir_p Ray::TMP_DIR
117
+ @extension = Ray::Zip.new({ :name => "dummy" })
118
+ end
119
+
120
+ after { cleanup }
121
+
122
+ it "must raise if the extension is not disabled" do
123
+ proc { @extension.enable }.must_raise RuntimeError
124
+ end
125
+
126
+ it "must enable the extension" do
127
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/.disabled/dummy"
128
+ @extension.enable
129
+ File.exist?("#{Ray::EXT_DIR}/dummy/dummy_extension.rb").must_equal true
130
+ end
131
+
132
+ end
133
+
134
+ describe "uninstall" do
135
+
136
+ before do
137
+ FileUtils.mkdir_p Ray::EXT_DIR
138
+ FileUtils.mkdir_p Ray::TMP_DIR
139
+ @extension = Ray::Zip.new({ :name => "dummy" })
140
+ end
141
+
142
+ after { cleanup }
143
+
144
+ it "must raise if the extension is not installed" do
145
+ proc { @extension.uninstall }.must_raise RuntimeError
146
+ end
147
+
148
+ it "must uninstall the extension" do
149
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/dummy"
150
+ @extension.uninstall
151
+ File.exist?("#{Ray::EXT_DIR}/dummy/dummy_extension.rb").must_equal false
152
+ end
153
+
154
+ end
155
+
156
+ describe "load_tasks" do
157
+
158
+ before do
159
+ FileUtils.mkdir_p Ray::EXT_DIR
160
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/dummy"
161
+ end
162
+
163
+ after { cleanup }
164
+
165
+ it "must load available Rake tasks" do
166
+ tasks = Ray::Zip.new({ :name => "dummy" }).load_tasks - ["default", "spec", "spec:cli"]
167
+ tasks.must_equal ["radiant:extensions:dummy:migrate", "radiant:extensions:dummy:sync", "radiant:extensions:dummy:update"]
168
+ end
169
+
170
+ end
171
+
172
+ describe "run_task" do
173
+
174
+ before do
175
+ FileUtils.mkdir_p Ray::EXT_DIR
176
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/dummy"
177
+ end
178
+
179
+ after { cleanup }
180
+
181
+ it "must run Rake tasks" do
182
+ task = Ray::Zip.new({ :name => "dummy" }).run_task "migrate"
183
+ task.must_equal ""
184
+ end
185
+
186
+ end
187
+
188
+ describe "run_tasks" do
189
+
190
+ before do
191
+ FileUtils.mkdir_p Ray::EXT_DIR
192
+ FileUtils.cp_r "#{Dir.pwd}/spec/fixtures/dummy", "#{Ray::EXT_DIR}/dummy"
193
+ end
194
+
195
+ after { cleanup }
196
+
197
+ it "must run the appropriate Rake tasks" do
198
+ extension = Ray::Zip.new({ :name => "dummy" })
199
+ tasks = extension.run_tasks - ["default", "spec", "spec:cli"]
200
+ tasks.must_equal ["radiant:extensions:dummy:migrate", "radiant:extensions:dummy:sync", "radiant:extensions:dummy:update"]
201
+ end
202
+
203
+ end
204
+
205
+ describe "name=" do
206
+
207
+ it "must convert the name to a proper extension name" do
208
+ extension = Ray::Zip.new
209
+ extension.name = "what-ever"
210
+ extension.name.must_equal "what_ever"
211
+ extension.name = "radiant-what-ever"
212
+ extension.name.must_equal "what_ever"
213
+ extension.name = "what-ever-extension"
214
+ extension.name.must_equal "what_ever"
215
+ extension.name = "radiant-what-ever-extension"
216
+ extension.name.must_equal "what_ever"
217
+ extension.name = "what_ever"
218
+ extension.name.must_equal "what_ever"
219
+ extension.name = "radiant_what_ever"
220
+ extension.name.must_equal "what_ever"
221
+ extension.name = "what_ever_extension"
222
+ extension.name.must_equal "what_ever"
223
+ extension.name = "radiant_what_ever_extension"
224
+ extension.name.must_equal "what_ever"
225
+ extension.name = "whatever"
226
+ extension.name.must_equal "whatever"
227
+ extension.name = "radiant_whatever"
228
+ extension.name.must_equal "whatever"
229
+ extension.name = "whatever_extension"
230
+ extension.name.must_equal "whatever"
231
+ extension.name = "radiant_whatever_extension"
232
+ extension.name.must_equal "whatever"
233
+ extension.name = "RADIANT-WHAT-EVER-EXTENSION"
234
+ extension.name.must_equal "what_ever"
235
+ end
236
+
237
+ end
238
+
239
+ end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+ require "ray/search/cache"
3
+
4
+ describe Ray::Cache do
5
+
6
+ describe "new" do
7
+
8
+ before do
9
+ FileUtils.mkdir_p Ray::RAY
10
+ FileUtils.cp "#{Dir.pwd}/spec/fixtures/cache_single.yml", Ray::CACHE
11
+ end
12
+
13
+ after { cleanup }
14
+
15
+ it "must have search results when there are matches" do
16
+ search = Ray::Cache.new "reorder-children"
17
+ search.results.must_equal({
18
+ "reorder_children" => {
19
+ :author => "Benny Degezelle",
20
+ :description => "Makes Radiant better by adding reorder_children!",
21
+ :homepage => "http://github.com/jomz/radiant-reorder_children-extension",
22
+ :name => "reorder_children",
23
+ :uri => "http://rubygems.org/gems/radiant-reorder_children-extension-1.0.5.gem",
24
+ :version => "1.0.5"
25
+ }
26
+ })
27
+ end
28
+
29
+ it "won't have search results when there are no matches" do
30
+ search = Ray::Cache.new "no-matches"
31
+ search.results.must_equal({})
32
+ end
33
+
34
+ it "won't have search results when there is no cache" do
35
+ FileUtils.rm_r Ray::RAY
36
+ search = Ray::Cache.new "no-matches"
37
+ search.results.must_equal({})
38
+ end
39
+
40
+ end
41
+
42
+ describe "clear" do
43
+
44
+ before do
45
+ FileUtils.mkdir_p Ray::RAY
46
+ FileUtils.cp "#{Dir.pwd}/spec/fixtures/cache_single.yml", Ray::CACHE
47
+ end
48
+
49
+ after { cleanup }
50
+
51
+ it "must clear the cache" do
52
+ Ray::Cache.clear
53
+ File.exist?(Ray::CACHE).must_equal false
54
+ end
55
+
56
+ end
57
+
58
+ describe "match?" do
59
+
60
+ it "must match by name or description" do
61
+ search = Ray::Cache.new "match"
62
+ search.match?("this", "will match").must_equal true
63
+ search.match?("match", "this will").must_equal true
64
+ end
65
+
66
+ it "must match by proper extension name" do
67
+ search = Ray::Cache.new "match-by-name"
68
+ search.match?("match_by_name", "").must_equal true
69
+ search.match?("", "match_by_name").must_equal false
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,137 @@
1
+ require "spec_helper"
2
+ require "ray/search/github"
3
+
4
+ describe Ray::GitHub do
5
+
6
+ describe "new" do
7
+
8
+ it "must have search results when there are matches" do
9
+ VCR.use_cassette("github_v2_api_search_single") do
10
+ search = Ray::GitHub.new "ray"
11
+ search.results.must_equal({
12
+ "ray" => {
13
+ :author => "john muhl",
14
+ :description => "friendly extension management for radiant cms using git or http.",
15
+ :homepage => "https://github.com/johnmuhl/radiant-ray-extension",
16
+ :name => "ray",
17
+ :uri => "https://github.com/johnmuhl/radiant-ray-extension",
18
+ :version => "latest"
19
+ }
20
+ })
21
+ end
22
+ end
23
+
24
+ it "won't have search results when there are no matches" do
25
+ VCR.use_cassette("github_v2_api_search_no_matches") do
26
+ search = Ray::GitHub.new "no-matches"
27
+ search.results.must_equal({})
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ describe "real_name" do
34
+
35
+ it "must find the repository owner's real name" do
36
+ VCR.use_cassette("github_v3_api_owner_name") do
37
+ search = Ray::GitHub.new "ray"
38
+ search.real_name("johnmuhl").must_equal "john muhl"
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ describe "cache" do
45
+
46
+ before do
47
+ FileUtils.mkdir_p Ray::RAY
48
+ VCR.use_cassette("github_v2_api_search_single") do
49
+ @search = Ray::GitHub.new "ray"
50
+ end
51
+ end
52
+
53
+ after { cleanup }
54
+
55
+ it "must create the cache in none exist" do
56
+ @search.cache
57
+ File.exist?(Ray::CACHE).must_equal true
58
+ end
59
+
60
+ it "must cache search" do
61
+ @search.cache
62
+ cache = YAML.load_file Ray::CACHE
63
+ cache.must_equal @search.results
64
+ end
65
+
66
+ it "must add to an existing cache" do
67
+ FileUtils.mkdir_p Ray::RAY
68
+ FileUtils.cp "#{Dir.pwd}/spec/fixtures/cache_single.yml", Ray::CACHE
69
+ old_cache = YAML.load_file Ray::CACHE
70
+ @search.cache
71
+ cache = YAML.load_file Ray::CACHE
72
+ cache.must_equal old_cache.merge(@search.results)
73
+ end
74
+
75
+ it "must update existing cache entries" do
76
+ FileUtils.mkdir_p Ray::RAY
77
+ FileUtils.cp "#{Dir.pwd}/spec/fixtures/cache_single.yml", Ray::CACHE
78
+ VCR.use_cassette("github_v2_api_search_reorder_children") do
79
+ search = Ray::GitHub.new "reorder_children"
80
+ search.cache
81
+ cache = YAML.load_file Ray::CACHE
82
+ cache.must_equal search.results
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ describe "output" do
89
+
90
+ it "must output formatted search results" do
91
+ VCR.use_cassette("github_v2_api_search_single") do
92
+ search = Ray::GitHub.new "ray"
93
+ search.output.must_match /ray install ray/
94
+ end
95
+ end
96
+
97
+ it "must output an explaination when there are no search results" do
98
+ VCR.use_cassette("github_v2_api_no_matches") do
99
+ search = Ray::GitHub.new "no-matches"
100
+ search.output.must_match /no extensions matched/i
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ describe "merge" do
107
+
108
+ it "must merge search results" do
109
+ VCR.use_cassette("github_v2_api_search_single") do
110
+ @first = Ray::GitHub.new "ray"
111
+ end
112
+ VCR.use_cassette("github_v2_api_search_reorder_children") do
113
+ @second = Ray::GitHub.new "reorder_children"
114
+ end
115
+ @first.merge(@second).results.must_equal({
116
+ "ray" => {
117
+ :author => "john muhl",
118
+ :description => "friendly extension management for radiant cms using git or http.",
119
+ :homepage => "https://github.com/johnmuhl/radiant-ray-extension",
120
+ :name => "ray",
121
+ :uri => "https://github.com/johnmuhl/radiant-ray-extension",
122
+ :version => "latest"
123
+ },
124
+ "reorder_children" => {
125
+ :author => "Benny Degezelle",
126
+ :description => "Adds the ability to reorder the children of a certain page with drag and drop.",
127
+ :homepage => "https://github.com/jomz/radiant-reorder_children-extension",
128
+ :name => "reorder_children",
129
+ :uri => "https://github.com/jomz/radiant-reorder_children-extension",
130
+ :version => "latest"
131
+ }
132
+ })
133
+ end
134
+
135
+ end
136
+
137
+ end