PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/spec/mediawiki_api_spec.rb

https://github.com/njh/dbpedialite
Ruby | 55 lines | 41 code | 13 blank | 1 comment | 11 complexity | 0bfc9f25a9786171f9a7c9157ce05e1b MD5 | raw file
  1. # encoding: utf-8
  2. require 'spec_helper'
  3. require 'mediawiki_api'
  4. describe MediaWikiApi do
  5. context "escaping a page title" do
  6. it "should convert 'AC/DC' to 'AC/DC'" do
  7. MediaWikiApi.escape_title('AC/DC').should == 'AC/DC'
  8. end
  9. it "should convert 'Category:Villages in Fife' to 'Category:Villages_in_Fife'" do
  10. MediaWikiApi.escape_title('Category:Villages in Fife').should == 'Category:Villages_in_Fife'
  11. end
  12. it "should convert 'Who Censored Roger Rabbit?' to 'Who_Censored_Roger_Rabbit%3F'" do
  13. MediaWikiApi.escape_title('Who Censored Roger Rabbit?').should == 'Who_Censored_Roger_Rabbit%3F'
  14. end
  15. it "should convert '100% (song)' to '100%25_(song)'" do
  16. MediaWikiApi.escape_title('100% (song)').should == '100%25_(song)'
  17. end
  18. it "should convert 'C#' to 'C%23'" do
  19. MediaWikiApi.escape_title('C#').should == 'C%23'
  20. end
  21. it "should convert '2 + 2 = 5' to 'C%23'" do
  22. MediaWikiApi.escape_title('2 + 2 = 5').should == '2_%2B_2_%3D_5'
  23. end
  24. it "should convert 'Nat \"King\" Cole' to 'Nat_%22King%22_Cole'" do
  25. MediaWikiApi.escape_title('Nat "King" Cole').should == 'Nat_%22King%22_Cole'
  26. end
  27. it "should not convert '—We Also Walk Dogs' to '—We_Also_Walk_Dogs'" do
  28. MediaWikiApi.escape_title('—We Also Walk Dogs').force_encoding('utf-8').should == '—We_Also_Walk_Dogs'
  29. end
  30. end
  31. context "escaping a query parameter" do
  32. it "should convert 'Florence + the Machine' to 'Florence%20%2B%20the%20Machine'" do
  33. MediaWikiApi.escape_query('Florence + the Machine').should == 'Florence%20%2B%20the%20Machine'
  34. end
  35. it "should convert 'C#' to 'C%23'" do
  36. MediaWikiApi.escape_query('C#').should == 'C%23'
  37. end
  38. it "should convert 'Café' to 'Café'" do
  39. MediaWikiApi.escape_query('Café').should == 'Caf%C3%A9'
  40. end
  41. end
  42. end