mediawiki-gateway 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjkxNDFhNzdhOGU1ZjU2YjIwNjA5YmI5MDQzYTg3YjBjZjMwNWI1Mg==
5
- data.tar.gz: !binary |-
6
- OWE3MjhiNjU1N2I2NzE4NWRmMGZmNmI0MGYyYmZhNTI5NjkyYmY5Ng==
2
+ SHA1:
3
+ metadata.gz: 2024bd23d67918a2bf7d38216a70da0bf8f60cb4
4
+ data.tar.gz: a0a8252820764951697436d9b957126b4f9f3c83
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZDRhMGVkZGM3ODI4MDg4MTRhNDU0NDU1YzdmZDhkZTBmNjhhZjg4NTE2ZGMy
10
- ZjE0MGE5NTQ5NTFmOTU0ODEyODE4MTUzMjE0ODM5ODcxZDkxZDQ0MGE0NTBh
11
- NzM1N2UxOGRlNDJmMzkyYzk1ODg5ODlhNjQyYjUxYmQyMTdjY2M=
12
- data.tar.gz: !binary |-
13
- MTI4N2Q2Y2Q2ZmYzNjdhMjBmNGQ5MzcwNzczMzRhYzdjMDNkNWIyYjNiYmU0
14
- OTRiZjkzMzVkOWFkNzliOTI3OTdmYjg3MjMzMjRmOTY4ZWQxMjU0ZGYzZDEy
15
- ZWY4NTQ3OTdlNWQxY2ViZjkyZWMyM2U0YmJiZDFlMTAzMTE1M2I=
6
+ metadata.gz: c84e686ef4362878482dddb8decd812a3886442388fc243c6fe2a35719a1326691ab1d0cd6b0c94c78a07a5004e013761a083877363c34e45035b093f41612f2
7
+ data.tar.gz: e3e8f94661cae3ba07edba0eb5b2a6a67d41e4359fc620cecb6b4688f8f6db8014eea597aeae2bb493e6ca445d8f1536a362386a126b88a79c83b752a41ccbda
data/README.md CHANGED
@@ -40,13 +40,17 @@ To build and install the gem use:
40
40
 
41
41
  bundle exec rake install
42
42
 
43
+ ### Testing against a live MediaWiki instance
44
+
45
+ You need to have [Docker](https://docker.com) and [mediawiki-testwiki](https://rubygems.org/gems/mediawiki-testwiki) installed.
46
+
43
47
  ## Status
44
48
 
45
49
  This gem is no longer in active development. Pull requests that fix bugs or add new features are more than welcome, but asking for new features is unlikely to make them materialize out of thin air.
46
50
 
47
51
  ## Credits
48
52
 
49
- Maintained by Jani Patokallio.
53
+ Loosely maintained by Jani Patokallio and [Jens Wille](https://github.com/blackwinter). If you'd be seriously interested in joining as an active maintainer, drop us a line!
50
54
 
51
55
  Thanks to:
52
56
  * John Carney, Mike Williams, Daniel Heath and the rest of the Lonely Planet Atlas team.
@@ -668,6 +668,26 @@ module MediaWiki
668
668
  )).first
669
669
  end
670
670
 
671
+ # Get the wiki's siteinfo as a hash. See http://www.mediawiki.org/wiki/API:Siteinfo.
672
+ #
673
+ # [options] Hash of additional options
674
+ def siteinfo(options = {})
675
+ res = make_api_request(options.merge(
676
+ 'action' => 'query',
677
+ 'meta' => 'siteinfo'
678
+ )).first
679
+
680
+ REXML::XPath.first(res, '//query/general')
681
+ .attributes.each_with_object({}) { |(k, v), h| h[k] = v }
682
+ end
683
+
684
+ # Get the wiki's MediaWiki version.
685
+ #
686
+ # [options] Hash of additional options passed to #siteinfo
687
+ def version(options = {})
688
+ siteinfo(options).fetch('generator', '').split.last
689
+ end
690
+
671
691
  # Get a list of all known namespaces
672
692
  #
673
693
  # [options] Hash of additional options
data/lib/media_wiki.rb CHANGED
@@ -5,5 +5,5 @@ require File.dirname(__FILE__) + '/media_wiki/utils'
5
5
  require File.dirname(__FILE__) + '/media_wiki/gateway'
6
6
 
7
7
  module MediaWiki
8
- VERSION = "0.6.1"
8
+ VERSION = "0.6.2"
9
9
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mediawiki-gateway 0.6.1 ruby lib
5
+ # stub: mediawiki-gateway 0.6.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "mediawiki-gateway"
9
- s.version = "0.6.1"
9
+ s.version = "0.6.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Jani Patokallio"]
14
- s.date = "2014-07-28"
14
+ s.date = "2014-09-29"
15
15
  s.description = ""
16
16
  s.email = "jpatokal@iki.fi"
17
17
  s.extra_rdoc_files = [
@@ -51,11 +51,12 @@ Gem::Specification.new do |s|
51
51
  "spec/fake_media_wiki/query_handling.rb",
52
52
  "spec/gateway_spec.rb",
53
53
  "spec/import-test-data.xml",
54
+ "spec/live_gateway_spec.rb",
54
55
  "spec/spec_helper.rb",
55
56
  "spec/utils_spec.rb"
56
57
  ]
57
58
  s.homepage = "http://github.com/jpatokal/mediawiki-gateway"
58
- s.rubygems_version = "2.2.2"
59
+ s.rubygems_version = "2.4.1"
59
60
  s.summary = "Connect to the mediawiki API"
60
61
 
61
62
  if s.respond_to? :specification_version then
@@ -91,9 +91,16 @@ module FakeMediaWiki
91
91
  end
92
92
 
93
93
  def siteinfo
94
- siteinfo_type = params[:siprop].to_sym
95
- return send(siteinfo_type) if respond_to?(siteinfo_type)
96
- halt(404, "Page not found")
94
+ if siteinfo_type = params[:siprop]
95
+ return send(siteinfo_type) if respond_to?(siteinfo_type)
96
+ halt(404, "Page not found")
97
+ else
98
+ api_response do |_|
99
+ _.query do
100
+ _.general(generator: "MediaWiki #{MediaWiki::VERSION}")
101
+ end
102
+ end
103
+ end
97
104
  end
98
105
 
99
106
  def namespaces
data/spec/gateway_spec.rb CHANGED
@@ -719,6 +719,32 @@ describe MediaWiki::Gateway do
719
719
 
720
720
  end
721
721
 
722
+ describe "#siteinfo" do
723
+
724
+ before do
725
+ $fake_media_wiki.reset
726
+ @siteinfo = @gateway.siteinfo
727
+ end
728
+
729
+ it "should get the siteinfo" do
730
+ @siteinfo.should == { 'generator' => "MediaWiki #{MediaWiki::VERSION}" }
731
+ end
732
+
733
+ end
734
+
735
+ describe "#version" do
736
+
737
+ before do
738
+ $fake_media_wiki.reset
739
+ @version = @gateway.version
740
+ end
741
+
742
+ it "should get the version" do
743
+ @version.should == MediaWiki::VERSION
744
+ end
745
+
746
+ end
747
+
722
748
  describe "#namespaces_by_prefix" do
723
749
 
724
750
  before do
@@ -0,0 +1,765 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'live gateway' do
4
+
5
+ def reset(*args, &block)
6
+ return unless respond_to?(:live_media_wiki_reset, true)
7
+ @gateway, @user, @pass = live_media_wiki_reset(*args, &block)
8
+ end
9
+
10
+ before do
11
+ reset
12
+ end
13
+
14
+ it 'should match requested version' do |example|
15
+ @gateway.version.should == example.metadata[:version]
16
+ end
17
+
18
+ describe '#login' do
19
+
20
+ describe 'with a valid username & password' do
21
+
22
+ it 'should login successfully with the default domain' do
23
+ @gateway.login(@user, @pass).should == @user
24
+ end
25
+
26
+ end
27
+
28
+ describe 'with a non-existent username' do
29
+
30
+ it 'should raise an error' do
31
+ lambda {
32
+ @gateway.login(@user.swapcase, @pass)
33
+ }.should raise_error(MediaWiki::Unauthorized)
34
+ end
35
+
36
+ end
37
+
38
+ describe 'with an incorrect password' do
39
+
40
+ it 'should raise an error' do
41
+ lambda {
42
+ @gateway.login(@user, @pass.swapcase)
43
+ }.should raise_error(MediaWiki::Unauthorized)
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ describe '#get_token' do
51
+
52
+ before do
53
+ @blank_token = '+\\'
54
+ end
55
+
56
+ describe 'when not logged in' do
57
+
58
+ describe 'requesting an edit token' do
59
+
60
+ it 'should return a blank token' do
61
+ token = @gateway.send(:get_token, 'edit', 'Main Page')
62
+
63
+ token.should_not be_nil
64
+ token.should == @blank_token
65
+ end
66
+
67
+ end
68
+
69
+ describe 'requesting an import token' do
70
+
71
+ it 'should raise an error' do
72
+ lambda {
73
+ @gateway.send(:get_token, 'import', 'Main Page')
74
+ }.should raise_error(MediaWiki::APIError, /not allowed/)
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
81
+ describe 'when logged in as admin user' do
82
+
83
+ before do
84
+ @gateway.login(@user, @pass)
85
+ end
86
+
87
+ describe 'requesting an edit token for a single page' do
88
+
89
+ it 'should return a token' do
90
+ token = @gateway.send(:get_token, 'edit', 'Main Page')
91
+
92
+ token.should_not be_nil
93
+ token.should_not == @blank_token
94
+ end
95
+
96
+ end
97
+
98
+ describe 'requesting an edit token for multiple pages' do
99
+
100
+ it 'should return a token' do
101
+ token = @gateway.send(:get_token, 'edit', 'Main Page|Another Page')
102
+
103
+ token.should_not be_nil
104
+ token.should_not == @blank_token
105
+ end
106
+
107
+ end
108
+
109
+ describe 'requesting an import token' do
110
+
111
+ it 'should return a token' do
112
+ token = @gateway.send(:get_token, 'import', 'Main Page')
113
+
114
+ token.should_not be_nil
115
+ token.should_not == @blank_token
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
122
+ end
123
+
124
+ describe '#get' do
125
+
126
+ describe 'for an existing wiki page' do
127
+
128
+ it 'returns raw page content' do
129
+ content = @gateway.get('Main Page')
130
+ content.should be_an_instance_of(String)
131
+ content.should include('MediaWiki has been successfully installed.') # XXX
132
+ end
133
+
134
+ end
135
+
136
+ describe 'for an existing empty wiki page' do
137
+
138
+ it 'returns an empty string', skip: '(page does not exist)' do
139
+ @gateway.get('Empty').should == ''
140
+ end
141
+
142
+ end
143
+
144
+ describe 'for a missing wiki page' do
145
+
146
+ it 'returns nil' do
147
+ @gateway.get('page/missing').should be_nil
148
+ end
149
+
150
+ end
151
+
152
+ describe 'for root (/)' do
153
+
154
+ it 'returns nil' do
155
+ @gateway.get('').should be_nil
156
+ end
157
+
158
+ end
159
+
160
+ describe 'when wiki returns 503' do
161
+
162
+ before do
163
+ @log = double(debug: nil, warn: nil)
164
+ @fail_gateway = live_media_wiki_gateway(maxlag: -1, retry_delay: 0)
165
+
166
+ allow(@fail_gateway).to receive(:log) { @log }
167
+ end
168
+
169
+ it 'should retry twice and fail', skip: 'expected Exception but nothing was raised' do
170
+ lambda { @fail_gateway.get('') }.should raise_error
171
+
172
+ @log.should have_received(:warn).with(
173
+ '503 Service Unavailable: Maxlag exceeded. Retry in 0 seconds.').twice
174
+ end
175
+
176
+ end
177
+
178
+ it 'should pass options to RestClient::Request' do
179
+ gateway = live_media_wiki_gateway({}, verify_ssl: false)
180
+
181
+ RestClient::Request.should receive(:execute).with(
182
+ hash_including(verify_ssl: false)).and_return([double(elements: {})])
183
+
184
+ gateway.get('').should be_nil
185
+ end
186
+
187
+ end
188
+
189
+ describe '#redirect?' do
190
+
191
+ describe 'for an existing redirect page' do
192
+
193
+ it 'returns true', skip: '(page does not exist)' do
194
+ @gateway.redirect?('Redirect').should == true
195
+ end
196
+
197
+ end
198
+
199
+ describe 'for an existing non-redirect page' do
200
+
201
+ it 'returns false' do
202
+ @gateway.redirect?('Main Page').should == false
203
+ end
204
+
205
+ end
206
+
207
+ describe 'for a missing wiki page' do
208
+
209
+ it 'returns false' do
210
+ @gateway.redirect?('page/missing').should == false
211
+ end
212
+
213
+ end
214
+
215
+ end
216
+
217
+ describe '#render' do
218
+
219
+ describe 'for an existing wiki page' do
220
+
221
+ it 'should return the page content' do
222
+ @gateway.render('Main Page').to_s.should include('MediaWiki has been successfully installed.') # XXX
223
+ end
224
+
225
+ it 'should raise an ArgumentError on illegal options' do
226
+ lambda {
227
+ @gateway.render('Main Page', doesnotexist: :at_all)
228
+ }.should raise_error(ArgumentError)
229
+ end
230
+
231
+ describe 'with option' do
232
+
233
+ it 'should strip img tags', skip: '(page does not exist)' do
234
+ page = @gateway.render('Foopage', noimages: true)
235
+
236
+ page.to_s.should == 'Sample <B>HTML</B> content.' <<
237
+ '<span class="editsection">[<a title="Edit section: Nomenclature" href="/w/index.php?title=Seat_of_local_government&amp;action=edit&amp;section=1">edit</a>]</span>' <<
238
+ '<a title="Interpreted language" href="/wiki/Interpreted_language">interpreted language</a>'
239
+ end
240
+
241
+ it 'should strip edit sections', skip: '(page does not exist)' do
242
+ page = @gateway.render('Foopage', noeditsections: true)
243
+
244
+ page.to_s.should == 'Sample <B>HTML</B> content.' <<
245
+ '<img width="150" height="150" class="thumbimage" src="http://upload.wikimedia.org/foo/Ruby_logo.svg" alt="Ruby logo.svg"/>' <<
246
+ '<a title="Interpreted language" href="/wiki/Interpreted_language">interpreted language</a>'
247
+ end
248
+
249
+ it 'should make all links absolute', skip: '(page does not exist)' do
250
+ page = @gateway.render('Foopage', linkbase: 'http://en.wikipedia.org')
251
+
252
+ page.to_s.should == 'Sample <B>HTML</B> content.' <<
253
+ '<img width="150" height="150" class="thumbimage" src="http://upload.wikimedia.org/foo/Ruby_logo.svg" alt="Ruby logo.svg"/>' <<
254
+ '<span class="editsection">[<a title="Edit section: Nomenclature" href="/w/index.php?title=Seat_of_local_government&amp;action=edit&amp;section=1">edit</a>]</span>' <<
255
+ '<a title="Interpreted language" href="http://en.wikipedia.org/wiki/Interpreted_language">interpreted language</a>'
256
+ end
257
+
258
+ end
259
+
260
+ end
261
+
262
+ describe 'for a missing wiki page' do
263
+
264
+ it 'should return nil', skip: 'missingtitle: The page you specified doesn\'t exist' do
265
+ @gateway.render('Invalidpage').should be_nil
266
+ end
267
+
268
+ end
269
+
270
+ end
271
+
272
+ describe '#create' do
273
+
274
+ before do
275
+ @gateway.login(@user, @pass)
276
+ end
277
+
278
+ describe 'when creating a new page' do
279
+
280
+ it 'should create the page' do
281
+ page = @gateway.create(title = 'A New Page', 'Some content')
282
+
283
+ hash = Hash.from_xml(page.first.to_s)['api']['edit']
284
+ hash['new'].should == ''
285
+ hash['title'].should == title
286
+ hash['result'].should == 'Success'
287
+ hash['newrevid'].to_i.should > hash['oldrevid'].to_i
288
+ end
289
+
290
+ end
291
+
292
+ describe 'when creating a page that already exists' do
293
+
294
+ before do
295
+ reset
296
+ end
297
+
298
+ describe 'and the `overwrite` option is set' do
299
+
300
+ it 'should overwrite the existing page' do
301
+ page = @gateway.create(title = 'Main Page', 'Some new content', summary: 'The summary', overwrite: true)
302
+
303
+ hash = Hash.from_xml(page.first.to_s)['api']['edit']
304
+ hash['new'].should be_nil
305
+ hash['title'].should == title
306
+ hash['result'].should == 'Success'
307
+ hash['newrevid'].to_i.should > hash['oldrevid'].to_i
308
+ end
309
+
310
+ end
311
+
312
+ describe 'and the `overwrite` option is not set' do
313
+
314
+ it 'should raise an error' do
315
+ lambda {
316
+ @gateway.create('Main Page', 'Some new content')
317
+ }.should raise_error(MediaWiki::APIError)
318
+ end
319
+
320
+ end
321
+
322
+ end
323
+
324
+ end
325
+
326
+ describe '#edit' do
327
+
328
+ it 'should overwrite the existing page', skip: '(result differs)' do
329
+ reset
330
+
331
+ page = @gateway.edit('Main Page', 'Some new content')
332
+
333
+ Hash.from_xml(page.first.to_s).should == Hash.from_xml(<<-EOT)
334
+ <api>
335
+ <edit result="Success" pageid="8" title="Main Page" oldrevid="1" newrevid="8"/>
336
+ </api>
337
+ EOT
338
+ end
339
+
340
+ end
341
+
342
+ describe '#upload' do
343
+
344
+ before do
345
+ @gateway.login(@user, @pass)
346
+ end
347
+
348
+ describe 'when uploading a new file', skip: 'badupload_file: File upload param file is not a file upload' do
349
+
350
+ before do
351
+ @path = 'some/path/sample_image.jpg'
352
+ allow(File).to receive(:new).with(@path).and_return('SAMPLEIMAGEDATA')
353
+
354
+ @page = @gateway.upload(@path)
355
+ end
356
+
357
+ it 'should open the file' do
358
+ File.should have_received(:new).with(@path)
359
+ end
360
+
361
+ it 'should upload the file' do
362
+ Hash.from_xml(@page.first.to_s).should == Hash.from_xml(<<-EOT)
363
+ <api>
364
+ <upload result="Success" filename="sample_image.jpg"/>
365
+ </api>
366
+ EOT
367
+ end
368
+
369
+ end
370
+
371
+ end
372
+
373
+ describe '#delete' do
374
+
375
+ def delete_page
376
+ title, content = 'Deletable Page', 'Some content'
377
+
378
+ @gateway.send(:make_api_request,
379
+ 'action' => 'edit',
380
+ 'title' => title,
381
+ 'text' => content,
382
+ 'summary' => '',
383
+ 'createonly' => '',
384
+ 'token' => @gateway.send(:get_token, 'edit', title)
385
+ )
386
+
387
+ yield lambda { @gateway.delete(title) }
388
+ end
389
+
390
+ describe 'when logged in as admin' do
391
+
392
+ describe 'and the page exists' do
393
+
394
+ it 'should delete the page' do
395
+ @gateway.login(@user, @pass)
396
+
397
+ delete_page { |block|
398
+ Hash.from_xml(block.call.first.to_s) == Hash.from_xml(<<-EOT)
399
+ <api>
400
+ <delete title="Deletable Page" reason="Default reason"/>
401
+ </api>
402
+ EOT
403
+ }
404
+ end
405
+
406
+ end
407
+
408
+ describe 'and the page does not exist' do
409
+
410
+ before do
411
+ @gateway.login(@user, @pass)
412
+ end
413
+
414
+ it 'should raise an error' do
415
+ lambda {
416
+ @gateway.delete('Missing Page')
417
+ }.should raise_error(MediaWiki::APIError)
418
+ end
419
+
420
+ end
421
+
422
+ end
423
+
424
+ describe 'when not logged in' do
425
+
426
+ it 'should raise an error' do
427
+ delete_page { |block| block.should raise_error(MediaWiki::APIError) }
428
+ end
429
+
430
+ end
431
+
432
+ end
433
+
434
+ describe '#undelete' do
435
+
436
+ describe 'when logged in as admin' do
437
+
438
+ before do
439
+ reset
440
+ @gateway.login(@user, @pass)
441
+ end
442
+
443
+ describe 'and the page no longer exists', skip: '(page does not exist)' do
444
+
445
+ before do
446
+ @revs = @gateway.undelete('Sandbox:Undeleted')
447
+ end
448
+
449
+ it 'should recreate the given page' do
450
+ @gateway.list('Sandbox:Undeleted').should == ['Sandbox:Undeleted']
451
+ end
452
+
453
+ it 'should report one undeleted revision' do
454
+ @revs.should == 1
455
+ end
456
+ end
457
+
458
+ describe 'but the page exists' do
459
+
460
+ before do
461
+ @revs = @gateway.undelete('Main Page')
462
+ end
463
+
464
+ it 'should report zero undeleted revisions' do
465
+ @revs.should == 0
466
+ end
467
+
468
+ end
469
+
470
+ end
471
+
472
+ describe 'when not logged in' do
473
+
474
+ it 'should raise an error' do
475
+ lambda {
476
+ @gateway.undelete('Undeletable Page')
477
+ }.should raise_error(MediaWiki::APIError)
478
+ end
479
+
480
+ end
481
+
482
+ end
483
+
484
+ describe '#list', skip: '(pages do not exist)' do
485
+
486
+ before do
487
+ reset
488
+ end
489
+
490
+ describe 'with an empty key' do
491
+
492
+ it 'should list all pages' do
493
+ @gateway.list('').sort.should == ['Book:Italy', 'Empty', 'Foopage', 'Level/Level/Index', 'Main 2', 'Main Page', 'Redirect']
494
+ end
495
+
496
+ end
497
+
498
+ describe 'with a namespace as the key' do
499
+
500
+ it 'should list all pages in the namespace' do
501
+ @gateway.list('Book:').should == ['Book:Italy']
502
+ end
503
+
504
+ end
505
+
506
+ describe 'with a partial title as the key' do
507
+
508
+ it 'should list all pages in the main namespace that start with key' do
509
+ @gateway.list('Main').sort.should == ['Main 2', 'Main Page']
510
+ end
511
+
512
+ end
513
+
514
+ end
515
+
516
+ describe '#search' do
517
+
518
+ before :all do
519
+ reset { |gateway|
520
+ gateway.create('Search Test', 'Foo KEY Blah')
521
+ gateway.create('Search Test 2', 'Zomp KEY Zorg')
522
+ gateway.create('Book:Search Test', 'Bar KEY Baz')
523
+ gateway.create('Sandbox:Search Test', 'Evil KEY Evil')
524
+ }
525
+ end
526
+
527
+ before do
528
+ # warning: srlimit may not be over 50 (set to 500) for users
529
+ @gateway = live_media_wiki_gateway(limit: 50)
530
+ end
531
+
532
+ describe 'with an empty key' do
533
+
534
+ it 'should raise an error' do
535
+ lambda {
536
+ @gateway.search('')
537
+ }.should raise_error(MediaWiki::APIError)
538
+ end
539
+
540
+ end
541
+
542
+ describe 'with a valid key and no namespaces', skip: '(searches all namespaces)' do
543
+
544
+ it 'should list all matching pages in the main namespace' do
545
+ @gateway.search('KEY').should =~ ['Search Test', 'Search Test 2']
546
+ end
547
+
548
+ end
549
+
550
+ describe 'with a valid key and a namespace string', skip: '(searches all namespaces)' do
551
+
552
+ it 'should list all matching pages in the specified namespaces' do
553
+ @gateway.search('KEY', 'Book').should == ['Book:Search Test']
554
+ end
555
+
556
+ end
557
+
558
+ describe 'with a valid key and a namespace array', skip: 'warning: Unrecognized values for parameter \'srnamespace\'' do
559
+
560
+ it 'should list all matching pages in the specified namespaces' do
561
+ @gateway.search('KEY', ['Book', 'Sandbox']).should =~ ['Sandbox:Search Test', 'Book:Search Test']
562
+ end
563
+
564
+ end
565
+
566
+ describe 'with maximum number of results' do
567
+
568
+ it 'should return at most the maximum number of results asked', skip: 'undefined method `to_i\' for sroffset=\'1\':REXML::Attribute' do
569
+ @gateway.search('KEY', nil, 2, 1).size.should == 1
570
+ end
571
+
572
+ end
573
+
574
+ end
575
+
576
+ describe '#namespaces_by_prefix' do
577
+
578
+ it 'should list all namespaces', skip: '(actual namespaces differ)' do
579
+ reset
580
+ @gateway.namespaces_by_prefix.should == { '' => 0, 'Book' => 100, 'Sandbox' => 200 }
581
+ end
582
+
583
+ end
584
+
585
+ describe '#semantic_query', skip: 'Semantic MediaWiki extension not installed' do
586
+
587
+ it 'should return an HTML string' do
588
+ response = @gateway.semantic_query('[[place::123]]', ['mainlabel=Page'])
589
+ response.should include('MediaWiki has been successfully installed.') # XXX
590
+ end
591
+
592
+ end
593
+
594
+ describe '#import' do
595
+
596
+ before do
597
+ @import_file = File.dirname(__FILE__) + '/import-test-data.xml'
598
+ end
599
+
600
+ describe 'when not logged in' do
601
+
602
+ it 'should raise an error' do
603
+ lambda {
604
+ @gateway.import(@import_file)
605
+ }.should raise_error(MediaWiki::APIError)
606
+ end
607
+
608
+ end
609
+
610
+ describe 'when logged in as admin' do
611
+
612
+ it 'should import content' do
613
+ @gateway.login(@user, @pass)
614
+
615
+ page = @gateway.import(@import_file)
616
+
617
+ Hash.from_xml(page.first.to_s) == Hash.from_xml(<<-EOT)
618
+ <api>
619
+ <import>
620
+ <page title="Main Page" ns="0" revisions="0"/>
621
+ <page title="Template:Header" ns="10" revisions="1"/>
622
+ </import>
623
+ </api>
624
+ EOT
625
+ end
626
+
627
+ end
628
+
629
+ end
630
+
631
+ describe '#export' do
632
+
633
+ it 'should return export data for the page' do
634
+ page = @gateway.export(title = 'Main Page')
635
+
636
+ hash = Hash.from_xml(page.to_s)['mediawiki']['page']
637
+ hash['id'].should_not be_nil
638
+ hash['title'].should == title
639
+ hash['revision'].should be_an_instance_of(Hash)
640
+ end
641
+
642
+ end
643
+
644
+ describe '#extensions' do
645
+
646
+ it 'should list all extensions', skip: '(extensions are not installed)' do
647
+ reset
648
+ @gateway.extensions.should == { 'FooExtension' => 'r1', 'BarExtension' => 'r2', 'Semantic MediaWiki' => '1.5' }
649
+ end
650
+
651
+ end
652
+
653
+ describe '#create_account' do
654
+
655
+ describe 'when logged in as admin' do
656
+
657
+ before do
658
+ @gateway.login(@user, @pass)
659
+ end
660
+
661
+ it 'should get expected result' do
662
+ page = @gateway.create_account('name' => name = 'FooBar', 'password' => 'BarBaz')
663
+
664
+ hash = Hash.from_xml(page.to_s)['api']['createaccount']
665
+ hash['token'].should_not be_nil
666
+ hash['userid'].should_not be_nil
667
+ hash['result'].should == 'Success'
668
+ hash['username'].should == name
669
+ end
670
+
671
+ end
672
+
673
+ end
674
+
675
+ describe '#options' do
676
+
677
+ describe 'when logged in' do
678
+
679
+ before do
680
+ @gateway.login(@user, @pass)
681
+ end
682
+
683
+ describe 'requesting an options token' do
684
+
685
+ it 'should return a token' do
686
+ token = @gateway.send(:get_options_token)
687
+
688
+ token.should_not be_nil
689
+ token.should_not == '+\\'
690
+ end
691
+
692
+ end
693
+
694
+ it 'should return the expected response', skip: 'warning: Validation error for \'realname\': cannot be set by this module' do
695
+ Hash.from_xml(@gateway.options(realname: 'Bar Baz').to_s).should == Hash.from_xml('<api options="success" />')
696
+ end
697
+
698
+ end
699
+
700
+ end
701
+
702
+ describe '#user_rights' do
703
+
704
+ describe 'when logged in as admin' do
705
+
706
+ before do
707
+ @gateway.login(@user, @pass)
708
+ end
709
+
710
+ describe 'requesting a userrights token for an existing user' do
711
+
712
+ it 'should return a token', skip: '(user does not exist)' do
713
+ token = @gateway.send(:get_userrights_token, 'nonadmin')
714
+
715
+ token.should_not be_nil
716
+ token.should_not == '+\\'
717
+ end
718
+ end
719
+
720
+ describe 'requesting a userrights token for an nonexistant user' do
721
+
722
+ it 'should raise an error' do
723
+ lambda {
724
+ @gateway.send(:get_userrights_token, 'nosuchuser')
725
+ }.should raise_error(MediaWiki::APIError)
726
+ end
727
+ end
728
+
729
+ describe "changing a user's groups with a valid token" do
730
+
731
+ it 'should return a result matching the input', skip: '(user does not exist)' do
732
+ token = @gateway.send(:get_userrights_token, 'nonadmin')
733
+ result = @gateway.send(:userrights, 'nonadmin', token, 'newgroup', 'oldgroup', 'because I can')
734
+
735
+ Hash.from_xml(@result.to_s).should == Hash.from_xml(<<-EOT)
736
+ <api>
737
+ <userrights user="nonadmin">
738
+ <removed>
739
+ <group>oldgroup</group>
740
+ </removed>
741
+ <added>
742
+ <group>newgroup</group>
743
+ </added>
744
+ </userrights>
745
+ </api>
746
+ EOT
747
+ end
748
+
749
+ end
750
+
751
+ end
752
+
753
+ end
754
+
755
+ end
756
+
757
+ unless (pool_size = Integer(ENV['LIVE_POOL_SIZE'] || 2)) > 1
758
+ warn 'Docker pool size must be greater than 1.'
759
+ else
760
+ ENV.fetch('LIVE_VERSION', '1.23.4').split(/[\s:,]/).each { |version|
761
+ describe_live(MediaWiki::Gateway, version: version, pool_size: pool_size) {
762
+ include_examples 'live gateway'
763
+ }
764
+ }
765
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,16 @@ RSpec.configure { |config|
11
11
  %w[expect mock].each { |what|
12
12
  config.send("#{what}_with", :rspec) { |c| c.syntax = [:should, :expect] }
13
13
  }
14
+
15
+ config.alias_example_group_to :describe_live, begin
16
+ require 'media_wiki/test_wiki/rspec_adapter'
17
+ rescue LoadError
18
+ { skip: 'MediaWiki::TestWiki not available'.tap { |msg|
19
+ warn "#{msg}. Install it with: gem install mediawiki-testwiki" } }
20
+ else
21
+ { live: true }.tap { |filter|
22
+ MediaWiki::TestWiki::RSpecAdapter.enhance(config, filter) }
23
+ end
14
24
  }
15
25
 
16
26
  # :nodoc: Rails 2.3.x: Hash#to_xml is defined in active_support
metadata CHANGED
@@ -1,209 +1,209 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki-gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jani Patokallio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-28 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: atomic
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jeweler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sham_rack
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rr
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '1.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec-core
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec-expectations
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rspec-mocks
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ! '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ! '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: debugger
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: sinatra
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ! '>='
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ! '>='
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: activemodel
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ! '>='
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ! '>='
206
+ - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  description: ''
@@ -214,8 +214,8 @@ extra_rdoc_files:
214
214
  - LICENSE
215
215
  - README.md
216
216
  files:
217
- - .ruby-version
218
- - .rvmrc
217
+ - ".ruby-version"
218
+ - ".rvmrc"
219
219
  - Gemfile
220
220
  - Gemfile.lock
221
221
  - LICENSE
@@ -246,6 +246,7 @@ files:
246
246
  - spec/fake_media_wiki/query_handling.rb
247
247
  - spec/gateway_spec.rb
248
248
  - spec/import-test-data.xml
249
+ - spec/live_gateway_spec.rb
249
250
  - spec/spec_helper.rb
250
251
  - spec/utils_spec.rb
251
252
  homepage: http://github.com/jpatokal/mediawiki-gateway
@@ -257,12 +258,12 @@ require_paths:
257
258
  - lib
258
259
  required_ruby_version: !ruby/object:Gem::Requirement
259
260
  requirements:
260
- - - ! '>='
261
+ - - ">="
261
262
  - !ruby/object:Gem::Version
262
263
  version: '0'
263
264
  required_rubygems_version: !ruby/object:Gem::Requirement
264
265
  requirements:
265
- - - ! '>='
266
+ - - ">="
266
267
  - !ruby/object:Gem::Version
267
268
  version: '0'
268
269
  requirements: []