oembed_provider 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +104 -0
  5. data/Rakefile +59 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/oembed_provider_controller.rb +55 -0
  8. data/config/routes.rb +8 -0
  9. data/lib/oembed_providable.rb +201 -0
  10. data/lib/oembed_provider.rb +91 -0
  11. data/lib/oembed_provider_helper.rb +18 -0
  12. data/rails/init.rb +1 -0
  13. data/test/full_2_3_5_app_with_tests/.gitignore +27 -0
  14. data/test/full_2_3_5_app_with_tests/README +1 -0
  15. data/test/full_2_3_5_app_with_tests/Rakefile +10 -0
  16. data/test/full_2_3_5_app_with_tests/app/controllers/application_controller.rb +7 -0
  17. data/test/full_2_3_5_app_with_tests/app/controllers/items_controller.rb +85 -0
  18. data/test/full_2_3_5_app_with_tests/app/controllers/photos_controller.rb +85 -0
  19. data/test/full_2_3_5_app_with_tests/app/helpers/application_helper.rb +4 -0
  20. data/test/full_2_3_5_app_with_tests/app/helpers/items_helper.rb +2 -0
  21. data/test/full_2_3_5_app_with_tests/app/helpers/photos_helper.rb +2 -0
  22. data/test/full_2_3_5_app_with_tests/app/models/item.rb +4 -0
  23. data/test/full_2_3_5_app_with_tests/app/models/photo.rb +4 -0
  24. data/test/full_2_3_5_app_with_tests/app/views/items/edit.html.erb +24 -0
  25. data/test/full_2_3_5_app_with_tests/app/views/items/index.html.erb +24 -0
  26. data/test/full_2_3_5_app_with_tests/app/views/items/new.html.erb +23 -0
  27. data/test/full_2_3_5_app_with_tests/app/views/items/show.html.erb +21 -0
  28. data/test/full_2_3_5_app_with_tests/app/views/layouts/items.html.erb +20 -0
  29. data/test/full_2_3_5_app_with_tests/app/views/layouts/photos.html.erb +18 -0
  30. data/test/full_2_3_5_app_with_tests/app/views/photos/edit.html.erb +12 -0
  31. data/test/full_2_3_5_app_with_tests/app/views/photos/index.html.erb +18 -0
  32. data/test/full_2_3_5_app_with_tests/app/views/photos/new.html.erb +11 -0
  33. data/test/full_2_3_5_app_with_tests/app/views/photos/show.html.erb +3 -0
  34. data/test/full_2_3_5_app_with_tests/config/boot.rb +110 -0
  35. data/test/full_2_3_5_app_with_tests/config/database.yml +22 -0
  36. data/test/full_2_3_5_app_with_tests/config/environment.rb +54 -0
  37. data/test/full_2_3_5_app_with_tests/config/environments/development.rb +17 -0
  38. data/test/full_2_3_5_app_with_tests/config/environments/production.rb +28 -0
  39. data/test/full_2_3_5_app_with_tests/config/environments/test.rb +28 -0
  40. data/test/full_2_3_5_app_with_tests/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/full_2_3_5_app_with_tests/config/initializers/inflections.rb +10 -0
  42. data/test/full_2_3_5_app_with_tests/config/initializers/mime_types.rb +5 -0
  43. data/test/full_2_3_5_app_with_tests/config/initializers/new_rails_defaults.rb +21 -0
  44. data/test/full_2_3_5_app_with_tests/config/initializers/oembed_provider.rb +2 -0
  45. data/test/full_2_3_5_app_with_tests/config/initializers/session_store.rb +15 -0
  46. data/test/full_2_3_5_app_with_tests/config/locales/en.yml +4 -0
  47. data/test/full_2_3_5_app_with_tests/config/locales/fr.yml +4 -0
  48. data/test/full_2_3_5_app_with_tests/config/locales/zh.yml +4 -0
  49. data/test/full_2_3_5_app_with_tests/config/locales.yml +5 -0
  50. data/test/full_2_3_5_app_with_tests/config/routes.rb +4 -0
  51. data/test/full_2_3_5_app_with_tests/db/migrate/20110212010602_create_items.rb +13 -0
  52. data/test/full_2_3_5_app_with_tests/db/migrate/20110212022722_create_photos.rb +15 -0
  53. data/test/full_2_3_5_app_with_tests/db/schema.rb +35 -0
  54. data/test/full_2_3_5_app_with_tests/db/seeds.rb +7 -0
  55. data/test/full_2_3_5_app_with_tests/doc/README_FOR_APP +2 -0
  56. data/test/full_2_3_5_app_with_tests/public/404.html +30 -0
  57. data/test/full_2_3_5_app_with_tests/public/422.html +30 -0
  58. data/test/full_2_3_5_app_with_tests/public/500.html +30 -0
  59. data/test/full_2_3_5_app_with_tests/public/favicon.ico +0 -0
  60. data/test/full_2_3_5_app_with_tests/public/images/rails.png +0 -0
  61. data/test/full_2_3_5_app_with_tests/public/index.html +275 -0
  62. data/test/full_2_3_5_app_with_tests/public/javascripts/application.js +2 -0
  63. data/test/full_2_3_5_app_with_tests/public/javascripts/controls.js +963 -0
  64. data/test/full_2_3_5_app_with_tests/public/javascripts/dragdrop.js +973 -0
  65. data/test/full_2_3_5_app_with_tests/public/javascripts/effects.js +1128 -0
  66. data/test/full_2_3_5_app_with_tests/public/javascripts/prototype.js +4320 -0
  67. data/test/full_2_3_5_app_with_tests/public/robots.txt +5 -0
  68. data/test/full_2_3_5_app_with_tests/public/stylesheets/scaffold.css +54 -0
  69. data/test/full_2_3_5_app_with_tests/script/about +4 -0
  70. data/test/full_2_3_5_app_with_tests/script/console +3 -0
  71. data/test/full_2_3_5_app_with_tests/script/dbconsole +3 -0
  72. data/test/full_2_3_5_app_with_tests/script/destroy +3 -0
  73. data/test/full_2_3_5_app_with_tests/script/generate +3 -0
  74. data/test/full_2_3_5_app_with_tests/script/performance/benchmarker +3 -0
  75. data/test/full_2_3_5_app_with_tests/script/performance/profiler +3 -0
  76. data/test/full_2_3_5_app_with_tests/script/plugin +3 -0
  77. data/test/full_2_3_5_app_with_tests/script/runner +3 -0
  78. data/test/full_2_3_5_app_with_tests/script/server +3 -0
  79. data/test/full_2_3_5_app_with_tests/test/factories.rb +14 -0
  80. data/test/full_2_3_5_app_with_tests/test/functional/oembed_provider_controller_test.rb +34 -0
  81. data/test/full_2_3_5_app_with_tests/test/integration/oembed_test.rb +88 -0
  82. data/test/full_2_3_5_app_with_tests/test/performance/browsing_test.rb +9 -0
  83. data/test/full_2_3_5_app_with_tests/test/selenium.rb +83 -0
  84. data/test/full_2_3_5_app_with_tests/test/test_helper.rb +55 -0
  85. data/test/full_2_3_5_app_with_tests/test/unit/oembed_providable_test.rb +211 -0
  86. data/test/full_2_3_5_app_with_tests/test/unit/oembed_provider_test.rb +97 -0
  87. data/test/full_2_3_5_app_with_tests/tmp/restart.txt +0 -0
  88. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/init.rb +1 -0
  89. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/base.rb +31 -0
  90. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/force_extension.rb +57 -0
  91. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/locale.rb +70 -0
  92. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb +33 -0
  93. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/uuid_token.rb +78 -0
  94. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter.rb +94 -0
  95. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/force_extension_spec.rb +65 -0
  96. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/generation_spec.rb +367 -0
  97. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/pagination_extension_spec.rb +19 -0
  98. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/recognition_spec.rb +76 -0
  99. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/routing_filter_spec.rb +114 -0
  100. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/spec_helper.rb +108 -0
  101. metadata +238 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,14 @@
1
+ Factory.define :item do |f|
2
+ f.sequence(:label) { |n| "a label#{n}"}
3
+ f.sequence(:description) { |n| "a description#{n}"}
4
+ end
5
+
6
+ Factory.define :photo do |f|
7
+ f.sequence(:title) { |n| "a title#{n}"}
8
+ f.sequence(:url) { |n| "http://example.com/photo?id=#{n}"}
9
+ f.sequence(:width) { |n| "600"}
10
+ f.sequence(:height) { |n| "400"}
11
+ end
12
+ # f.sequence(:author_name) { |n| "an author_name#{n}"}
13
+ # f.sequence(:author_url) { |n| "http://example.com/author?id=#{n}"}
14
+
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class OembedProviderControllerTest < ActionController::TestCase
5
+ context "The oembed provider controller" do
6
+ setup do
7
+ @photo = Factory.create(:photo)
8
+ end
9
+
10
+ should "endpoint" do
11
+ get :endpoint, :url => "http://example.com/photos/#{@photo.id}"
12
+ assert_response :success
13
+ end
14
+
15
+ should "endpoint with format json" do
16
+ @request.accept = "text/javascript"
17
+ get :endpoint, :url => "http://example.com/photos/#{@photo.id}", :format => 'json'
18
+ assert_response :success
19
+ end
20
+
21
+ should "endpoint with format json and callback, return json-p" do
22
+ @request.accept = "text/javascript"
23
+ get :endpoint, :url => "http://example.com/photos/#{@photo.id}", :format => 'json', :callback => 'myCallback'
24
+ assert_response :success
25
+ end
26
+
27
+ should "endpoint with format xml" do
28
+ @request.accept = "text/xml"
29
+ get :endpoint, :url => "http://example.com/photos/#{@photo.id}", :format => 'xml'
30
+ assert_response :success
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,88 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ Webrat.configure do |config|
5
+ config.mode = :rails
6
+ end
7
+
8
+ class OembedTest < ActionController::IntegrationTest
9
+ context "A providable object when its url is request from the oembed endpoint" do
10
+ setup do
11
+ @photo = Factory.create(:photo)
12
+ @url_without_protocol = "example.com/photos/#{@photo.id}"
13
+ @escaped_url = "http%3A//#{@url_without_protocol}"
14
+ @normal_url = "http://#{@url_without_protocol}"
15
+ end
16
+
17
+ should "return correct json for the providable object" do
18
+ visit "/oembed?url=#{@escaped_url}"
19
+ assert_json_equal_to(response.body)
20
+ end
21
+
22
+ should "return correct json for the providable object when .json" do
23
+ visit "/oembed.json?url=#{@escaped_url}"
24
+ assert_json_equal_to(response.body)
25
+ end
26
+
27
+ should "return correct json for the providable object when query string specifies format=json" do
28
+ visit "/oembed?url=#{@escaped_url}&format=json"
29
+ assert_json_equal_to(response.body)
30
+ end
31
+
32
+ should "return correct json-p for the providable object when .json and callback specified" do
33
+ callback_name = 'myCallback'
34
+ visit "/oembed.json?url=#{@escaped_url}&callback=#{callback_name}"
35
+ assert response.body.include?(callback_name)
36
+ assert_json_equal_to(response.body.sub("#{callback_name}(", '').chomp(');'))
37
+ end
38
+
39
+ should "return correct json-p for the providable object when .json and variable specified" do
40
+ variable_name = 'myVar'
41
+ visit "/oembed.json?url=#{@escaped_url}&variable=#{variable_name}"
42
+ assert response.body.include?(variable_name)
43
+ assert_json_equal_to(response.body.sub("var #{variable_name} = ", '').chomp(';'))
44
+ end
45
+
46
+ should "return correct json-p for the providable object when .json and variable and callback specified" do
47
+ variable_name = 'myVar'
48
+ callback_name = 'myCallback'
49
+ visit "/oembed.json?url=#{@escaped_url}&variable=#{variable_name}&callback=#{callback_name}"
50
+ assert response.body.include?(variable_name)
51
+ assert response.body.include?(callback_name)
52
+ stripped_to_json = response.body.sub("var #{variable_name} = ", '').sub("\n#{callback_name}(#{variable_name})", '').chomp(';').chomp(';')
53
+ assert_json_equal_to(stripped_to_json)
54
+ end
55
+
56
+ should "return correct xml for the providable object when .xml" do
57
+ visit "/oembed.xml?url=#{@escaped_url}"
58
+ assert_equal @photo.oembed_response.to_xml, response.body
59
+ end
60
+
61
+ should "return correct xml for the providable object when query string specifies format=xml" do
62
+ visit "/oembed?url=#{@escaped_url}&format=xml"
63
+ assert_equal @photo.oembed_response.to_xml, response.body
64
+ end
65
+
66
+ # test helper here as integration test rather than unit/helpers
67
+ # only one helper and easier to do and effective in practice
68
+ context "when visiting providable url, the page" do
69
+ should "oembed links in the header" do
70
+ visit @normal_url
71
+ assert response.body.include?("application/json+oembed")
72
+ assert response.body.include?("/oembed?url=#{@escaped_url}")
73
+ assert response.body.include?("application/xml+oembed")
74
+ assert response.body.include?("/oembed.xml?url=#{@escaped_url}")
75
+ end
76
+ end
77
+
78
+ # WARNING: maxheight and maxwidth parameter passing
79
+ # results in correct version of image, etc.
80
+ # is left to application specific testing by application using the engine
81
+ # in other words, implement it in YOUR tests
82
+ end
83
+ private
84
+
85
+ def assert_json_equal_to(response_body)
86
+ assert_equal ActiveSupport::JSON.decode(@photo.oembed_response.to_json), ActiveSupport::JSON.decode(response_body)
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,83 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ # This file is not in integration/ because when run with
5
+ # 'rake', it causes segfaults in the test suite
6
+
7
+ # ATTN: Before runnings these tests, be sure to turn
8
+ # off all extensions and popup blockers in Safari
9
+
10
+ class ActiveSupport::TestCase
11
+ self.use_transactional_fixtures = true
12
+ setup do |session|
13
+ session.host! "localhost:3001"
14
+ end
15
+ end
16
+
17
+ Webrat.configure do |config|
18
+ config.mode = :selenium
19
+ config.application_environment = :test
20
+ config.selenium_browser_key = '*safari'
21
+ end
22
+
23
+ class SeleniumTest < ActionController::IntegrationTest
24
+ context "Using Selenium to test javascript functionality" do
25
+
26
+ # DEBUG: This works so if the others don't, try just this one
27
+ # should "be able to visit the homepage" do
28
+ # visit "/"
29
+ # assert_contain "Welcome aboard"
30
+ # end
31
+
32
+ should "be able to translate an item via AJAX" do
33
+ item = create_item
34
+ click_link "Français"
35
+ assert current_url =~ /\/en\/items\/#{item.id}$/
36
+ assert_contain "Translate from English to Français"
37
+ fill_in 'item_translation_label', :with => 'Certains Point'
38
+ click_button 'Create'
39
+ assert_contain 'Translation was successfully created.'
40
+ end
41
+
42
+ should "be able to switch translations" do
43
+ item = create_item
44
+ click_link "Français"
45
+ assert current_url =~ /\/en\/items\/#{item.id}$/
46
+ assert_contain "Translate from English to Français"
47
+ click_link "Suomi"
48
+ assert current_url =~ /\/en\/items\/#{item.id}$/
49
+ assert_contain "Translate from English to Suomi"
50
+ end
51
+
52
+ should "be able to close the translations box" do
53
+ item = create_item
54
+ click_link "Français"
55
+ click_link "[close]"
56
+ assert_not_contain "Translate from English to Français"
57
+ end
58
+
59
+ should "be able to use the auto translate functionality" do
60
+ item = create_item
61
+ visit "/en/items/#{item.id}/translations/new?to_locale=fr"
62
+ click_link '[auto translate]'
63
+ sleep 1 # ugly way to wait for google to do it's thing
64
+ click_button 'Create'
65
+ assert_contain 'Translation was successfully created.'
66
+ assert_contain 'Certains Point'
67
+ end
68
+
69
+ end
70
+
71
+ private
72
+
73
+ def create_item
74
+ visit "/en/items"
75
+ click_link "New item"
76
+ fill_in 'item_label', :with => 'Some Item'
77
+ fill_in 'item_value', :with => '$3.50'
78
+ fill_in 'item_locale', :with => 'en'
79
+ click_button 'Create'
80
+ assert_contain 'Item was successfully created.'
81
+ Item.last
82
+ end
83
+ end
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
+ require 'test_help'
5
+ require 'rubygems'
6
+ require 'shoulda'
7
+ require 'factory_girl'
8
+ require "webrat"
9
+
10
+ require File.expand_path(File.dirname(__FILE__) + "/factories")
11
+
12
+ Webrat.configure do |config|
13
+ config.mode = :rails
14
+ end
15
+
16
+ class ActiveSupport::TestCase
17
+ # Transactional fixtures accelerate your tests by wrapping each test method
18
+ # in a transaction that's rolled back on completion. This ensures that the
19
+ # test database remains unchanged so your fixtures don't have to be reloaded
20
+ # between every test method. Fewer database queries means faster tests.
21
+ #
22
+ # Read Mike Clark's excellent walkthrough at
23
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
24
+ #
25
+ # Every Active Record database supports transactions except MyISAM tables
26
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
27
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
28
+ # is recommended.
29
+ #
30
+ # The only drawback to using transactional fixtures is when you actually
31
+ # need to test transactions. Since your test is bracketed by a transaction,
32
+ # any transactions started in your code will be automatically rolled back.
33
+ # self.use_transactional_fixtures = true
34
+
35
+ # Instantiated fixtures are slow, but give you @david where otherwise you
36
+ # would need people(:david). If you don't want to migrate your existing
37
+ # test cases which use the @david style and don't mind the speed hit (each
38
+ # instantiated fixtures translates to a database query per test method),
39
+ # then set this back to true.
40
+ # self.use_instantiated_fixtures = false
41
+
42
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
43
+ #
44
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
45
+ # -- they do not yet inherit this setting
46
+ # fixtures :all
47
+
48
+ # Make sure that each test case has a teardown
49
+ # method to clear the db after each test.
50
+ def inherited(base)
51
+ base.define_method teardown do
52
+ super
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,211 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class OembedProvidableTest < ActiveSupport::TestCase
5
+ n = 0
6
+
7
+ context "A model class that includes OembedProvidable" do
8
+
9
+ context "when declaring oembed_providable_as" do
10
+ setup do
11
+ n += 1
12
+ @a_class_name = "Klass#{n}"
13
+
14
+ Object.const_set(@a_class_name, Class.new(ActiveRecord::Base)).class_eval do
15
+ include OembedProvidable
16
+ end
17
+
18
+ @a_class = @a_class_name.constantize
19
+ end
20
+
21
+ should "not be able to be able to declare oembed_providable_as without an argument for type" do
22
+ assert_raise(ArgumentError) { @a_class.send(:oembed_providable_as) }
23
+ end
24
+
25
+ should "be able to be able to declare oembed_providable_as with a type" do
26
+ assert_nothing_raised { @a_class.send(:oembed_providable_as, :link) }
27
+ end
28
+
29
+ should "be able to be able to declare oembed_providable_as with a type and a hash for a spec" do
30
+ assert_nothing_raised { @a_class.send(:oembed_providable_as, :link, { :title => :label }) }
31
+ end
32
+
33
+ should "have the ability to return an oembed_type" do
34
+ @a_class.send(:oembed_providable_as, :link)
35
+ assert @a_class.respond_to?(:oembed_type)
36
+ assert_equal @a_class.oembed_type, :link
37
+ end
38
+ end
39
+
40
+ context "will have method" do
41
+ setup do
42
+ @method_specs = Hash.new
43
+ end
44
+
45
+ context "methods_specs_for that" do
46
+ should "return an array of hashes that match defaults when there is no hash of overriding specs" do
47
+ assert_nothing_raised { Photo::OembedResponse.send(:method_specs_for, OembedProvider.optional_attributes) }
48
+ OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
49
+ results_for_test = Photo::OembedResponse.send(:method_specs_for, OembedProvider.optional_attributes)
50
+ assert_equal results_for_test, @method_specs
51
+ end
52
+
53
+ should "return an array of hashes that take into account overriding specs" do
54
+ OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
55
+ @method_specs[:title] = :label
56
+ results_for_test = Item::OembedResponse.send(:method_specs_for, OembedProvider.optional_attributes)
57
+ assert_equal results_for_test, @method_specs
58
+ end
59
+ end
60
+
61
+ context "optional_attributes_specs set and " do
62
+ should "match the OembedProvider defaults when there is no hash of overriding specs in the oembed_providable_as call" do
63
+ assert Photo::OembedResponse.respond_to?(:optional_attributes_specs)
64
+ OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
65
+ assert_equal Photo::OembedResponse.optional_attributes_specs, @method_specs
66
+ end
67
+
68
+ should "match the oembed_providable_as specs if they are specified" do
69
+ OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
70
+ @method_specs[:title] = :label
71
+ assert_equal Item::OembedResponse.optional_attributes_specs, @method_specs
72
+ end
73
+ end
74
+
75
+ context "required_attributes_specs set and " do
76
+ should "match the OembedProvider defaults when there is no hash of overriding specs in the oembed_providable_as call" do
77
+ assert Photo::OembedResponse.respond_to?(:required_attributes_specs)
78
+ OembedProvider.required_attributes[:photo].each { |attr| @method_specs[attr] = attr }
79
+ assert_equal Photo::OembedResponse.required_attributes_specs, @method_specs
80
+ end
81
+
82
+ should "match the oembed_providable_as specs if they are specified" do
83
+ Object.const_set("RichItem", Class.new(ActiveRecord::Base)).class_eval do
84
+ include OembedProvidable
85
+ oembed_providable_as :rich, :html => :description
86
+ def description
87
+ "<h1>some html</h1>"
88
+ end
89
+ end
90
+
91
+ OembedProvider.required_attributes[:rich].each { |attr| @method_specs[attr] = attr }
92
+ @method_specs[:html] = :description
93
+ assert_equal RichItem::OembedResponse.required_attributes_specs, @method_specs
94
+ end
95
+ end
96
+ context "providable_all_attributes set and " do
97
+ should "have all relevant attributes for the type" do
98
+ assert Item::OembedResponse.respond_to?(:providable_all_attributes)
99
+ all_attributes = OembedProvider.optional_attributes +
100
+ OembedProvider.required_attributes[:link] +
101
+ OembedProvider.base_attributes
102
+ assert_equal all_attributes, Item::OembedResponse.providable_all_attributes
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ context "A photo that includes OembedProvidable" do
109
+ setup do
110
+ @photo = Factory.create(:photo)
111
+ end
112
+
113
+ should "have an oembed_response object" do
114
+ assert @photo.oembed_response
115
+ end
116
+
117
+ should "have an oembed_max_dimensions object when maxheight and maxwidth are specified" do
118
+ maxheight = 400
119
+ maxwidth = 600
120
+ assert @photo.oembed_response(:maxheight => maxheight,
121
+ :maxwidth => maxwidth)
122
+ assert_equal maxheight, @photo.oembed_response.maxheight
123
+ assert_equal maxwidth, @photo.oembed_response.maxwidth
124
+
125
+ assert @photo.respond_to?(:oembed_max_dimensions)
126
+ assert_equal maxheight, @photo.oembed_max_dimensions[:height]
127
+ assert_equal maxwidth, @photo.oembed_max_dimensions[:width]
128
+ end
129
+
130
+ context "has an oembed_response and" do
131
+ setup do
132
+ @response = @photo.oembed_response
133
+ end
134
+
135
+ context "has required attribute that" do
136
+ should "be title" do
137
+ assert @response.title.present?
138
+ end
139
+
140
+ should "be version" do
141
+ assert @response.version.present?
142
+ end
143
+
144
+ should "be height" do
145
+ assert @response.height.present?
146
+ end
147
+
148
+ should "be width" do
149
+ assert @response.width.present?
150
+ end
151
+
152
+ should "be url" do
153
+ assert @response.url.present?
154
+ end
155
+
156
+ should "be provider_url" do
157
+ assert @response.provider_url.present?
158
+ end
159
+
160
+ should "be provider_name" do
161
+ assert @response.provider_name.present?
162
+ end
163
+ end
164
+
165
+ context "has can have optional attribute that" do
166
+ should "be author_name" do
167
+ @photo = Factory.create(:photo, :author_name => "Snappy")
168
+ assert @photo.oembed_response.author_name.present?
169
+ assert_equal "Snappy", @photo.oembed_response.author_name
170
+ end
171
+
172
+ should "be author_url" do
173
+ @photo = Factory.create(:photo, :author_url => "http://snapsnap.com")
174
+ assert @photo.oembed_response.author_url.present?
175
+ assert_equal "http://snapsnap.com", @photo.oembed_response.author_url
176
+ end
177
+
178
+ should "be thumbnail_url" do
179
+ @photo = Factory.create(:photo, :thumbnail_url => "http://snapsnap.com/thumb.jpg")
180
+ assert @photo.oembed_response.thumbnail_url.present?
181
+ assert_equal "http://snapsnap.com/thumb.jpg", @photo.oembed_response.thumbnail_url
182
+ end
183
+
184
+ should "be thumbnail_width" do
185
+ @photo = Factory.create(:photo, :thumbnail_width => 50)
186
+ assert @photo.oembed_response.thumbnail_width.present?
187
+ assert_equal 50, @photo.oembed_response.thumbnail_width
188
+ end
189
+
190
+ should "be thumbnail_height" do
191
+ @photo = Factory.create(:photo, :thumbnail_height => 50)
192
+ assert @photo.oembed_response.thumbnail_height.present?
193
+ assert_equal 50, @photo.oembed_response.thumbnail_height
194
+ end
195
+ end
196
+
197
+ context "when returning json" do
198
+ should "succeed" do
199
+ assert @response.as_json
200
+ assert !@response.to_json.to_s.include?(':null')
201
+ end
202
+ end
203
+
204
+ context "when returning xml" do
205
+ should "succeed" do
206
+ assert @response.to_xml
207
+ end
208
+ end
209
+ end
210
+ end
211
+ end