oembed_provider_engine 0.0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +82 -0
- data/Rakefile +40 -0
- data/app/controllers/oembed_provider_engine/application_controller.rb +2 -0
- data/app/controllers/oembed_provider_engine/oembed_provider_controller.rb +56 -0
- data/app/helpers/oembed_provider_engine/application_helper.rb +4 -0
- data/app/helpers/oembed_provider_engine/oembed_provider_helper.rb +20 -0
- data/app/models/oembed_provider_engine/oembed_providable.rb +204 -0
- data/app/models/oembed_provider_engine/oembed_provider.rb +95 -0
- data/app/views/layouts/oembed_provider_engine/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/lib/oembed_provider_engine/engine.rb +11 -0
- data/lib/oembed_provider_engine/version.rb +3 -0
- data/lib/oembed_provider_engine.rb +4 -0
- data/lib/tasks/oembed_providerengine_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/photos_controller.rb +11 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/item.rb +4 -0
- data/test/dummy/app/models/photo.rb +4 -0
- data/test/dummy/app/views/items/edit.html.erb +24 -0
- data/test/dummy/app/views/items/index.html.erb +24 -0
- data/test/dummy/app/views/items/new.html.erb +23 -0
- data/test/dummy/app/views/items/show.html.erb +21 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/items.html.erb +20 -0
- data/test/dummy/app/views/layouts/photos.html.erb +18 -0
- data/test/dummy/app/views/photos/edit.html.erb +12 -0
- data/test/dummy/app/views/photos/index.html.erb +18 -0
- data/test/dummy/app/views/photos/new.html.erb +11 -0
- data/test/dummy/app/views/photos/show.html.erb +3 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/oembed_provider.rb +2 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20110212010602_create_items.rb +13 -0
- data/test/dummy/db/migrate/20110212022722_create_photos.rb +15 -0
- data/test/dummy/db/schema.rb +37 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/factories/photos.rb +14 -0
- data/test/functional/oembed_provider_controller_test.rb +52 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/integration/oembed_test.rb +84 -0
- data/test/oembed_providable_test.rb +215 -0
- data/test/oembed_provider_test.rb +110 -0
- data/test/test_helper.rb +25 -0
- metadata +378 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OembedProvidableTest < ActiveSupport::TestCase
|
4
|
+
n = 0
|
5
|
+
context "A model class that includes OembedProvidable" do
|
6
|
+
|
7
|
+
context "when declaring oembed_providable_as" do
|
8
|
+
setup do
|
9
|
+
n += 1
|
10
|
+
@a_class_name = "Klass#{n}"
|
11
|
+
|
12
|
+
Object.const_set(@a_class_name, Class.new(ActiveRecord::Base)).class_eval do
|
13
|
+
include OembedProviderEngine::OembedProvidable
|
14
|
+
end
|
15
|
+
|
16
|
+
@a_class = @a_class_name.constantize
|
17
|
+
end
|
18
|
+
|
19
|
+
should "not be able to be able to declare oembed_providable_as without an argument for type" do
|
20
|
+
assert_raise(ArgumentError) { @a_class.send(:oembed_providable_as) }
|
21
|
+
end
|
22
|
+
|
23
|
+
should "be able to be able to declare oembed_providable_as with a type" do
|
24
|
+
assert_nothing_raised { @a_class.send(:oembed_providable_as, :link) }
|
25
|
+
end
|
26
|
+
|
27
|
+
should "be able to be able to declare oembed_providable_as with a type and a hash for a spec" do
|
28
|
+
assert_nothing_raised { @a_class.send(:oembed_providable_as, :link, { :title => :label }) }
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have the ability to return an oembed_type" do
|
32
|
+
@a_class.send(:oembed_providable_as, :link)
|
33
|
+
assert @a_class.respond_to?(:oembed_type)
|
34
|
+
assert_equal @a_class.oembed_type, :link
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "will have method" do
|
39
|
+
setup do
|
40
|
+
@method_specs = Hash.new
|
41
|
+
end
|
42
|
+
|
43
|
+
context "methods_specs_for that" do
|
44
|
+
should "return an array of hashes that match defaults when there is no hash of overriding specs" do
|
45
|
+
assert_nothing_raised { Photo::OembedResponse.send(:method_specs_for, OembedProviderEngine::OembedProvider.optional_attributes) }
|
46
|
+
OembedProviderEngine::OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
|
47
|
+
results_for_test = Photo::OembedResponse.send(:method_specs_for, OembedProviderEngine::OembedProvider.optional_attributes)
|
48
|
+
assert_equal results_for_test, @method_specs
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return an array of hashes that take into account overriding specs" do
|
52
|
+
OembedProviderEngine::OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
|
53
|
+
@method_specs[:title] = :label
|
54
|
+
results_for_test = Item::OembedResponse.send(:method_specs_for, OembedProviderEngine::OembedProvider.optional_attributes)
|
55
|
+
assert_equal results_for_test, @method_specs
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "optional_attributes_specs set and " do
|
60
|
+
should "match the OembedProvider defaults when there is no hash of overriding specs in the oembed_providable_as call" do
|
61
|
+
assert Photo::OembedResponse.respond_to?(:optional_attributes_specs)
|
62
|
+
OembedProviderEngine::OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
|
63
|
+
assert_equal Photo::OembedResponse.optional_attributes_specs, @method_specs
|
64
|
+
end
|
65
|
+
|
66
|
+
should "match the oembed_providable_as specs if they are specified" do
|
67
|
+
OembedProviderEngine::OembedProvider.optional_attributes.each { |attr| @method_specs[attr] = attr }
|
68
|
+
@method_specs[:title] = :label
|
69
|
+
assert_equal Item::OembedResponse.optional_attributes_specs, @method_specs
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "required_attributes_specs set and " do
|
74
|
+
should "match the OembedProvider defaults when there is no hash of overriding specs in the oembed_providable_as call" do
|
75
|
+
assert Photo::OembedResponse.respond_to?(:required_attributes_specs)
|
76
|
+
OembedProviderEngine::OembedProvider.required_attributes[:photo].each { |attr| @method_specs[attr] = attr }
|
77
|
+
assert_equal Photo::OembedResponse.required_attributes_specs, @method_specs
|
78
|
+
end
|
79
|
+
|
80
|
+
should "match the oembed_providable_as specs if they are specified" do
|
81
|
+
Object.const_set("RichItem", Class.new(ActiveRecord::Base)).class_eval do
|
82
|
+
include OembedProviderEngine::OembedProvidable
|
83
|
+
oembed_providable_as :rich, :html => :description
|
84
|
+
def description
|
85
|
+
"<h1>some html</h1>"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
OembedProviderEngine::OembedProvider.required_attributes[:rich].each { |attr| @method_specs[attr] = attr }
|
90
|
+
@method_specs[:html] = :description
|
91
|
+
assert_equal RichItem::OembedResponse.required_attributes_specs, @method_specs
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "providable_all_attributes set and " do
|
96
|
+
should "have all relevant attributes for the type" do
|
97
|
+
assert Item::OembedResponse.respond_to?(:providable_all_attributes)
|
98
|
+
all_attributes = OembedProviderEngine::OembedProvider.optional_attributes +
|
99
|
+
OembedProviderEngine::OembedProvider.required_attributes[:link] +
|
100
|
+
OembedProviderEngine::OembedProvider.base_attributes
|
101
|
+
assert_equal all_attributes, Item::OembedResponse.providable_all_attributes
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "A photo that includes OembedProvidable" do
|
108
|
+
setup do
|
109
|
+
@photo = FactoryGirl.create(:photo)
|
110
|
+
end
|
111
|
+
|
112
|
+
should "have an oembed_response object" do
|
113
|
+
assert @photo.oembed_response
|
114
|
+
end
|
115
|
+
|
116
|
+
should "have an oembed_max_dimensions object when maxheight and maxwidth are specified" do
|
117
|
+
maxheight = 400
|
118
|
+
maxwidth = 600
|
119
|
+
assert @photo.oembed_response(:maxheight => maxheight,
|
120
|
+
:maxwidth => maxwidth)
|
121
|
+
assert_equal maxheight, @photo.oembed_response.maxheight
|
122
|
+
assert_equal maxwidth, @photo.oembed_response.maxwidth
|
123
|
+
|
124
|
+
assert @photo.respond_to?(:oembed_max_dimensions)
|
125
|
+
assert_equal maxheight, @photo.oembed_max_dimensions[:height]
|
126
|
+
assert_equal maxwidth, @photo.oembed_max_dimensions[:width]
|
127
|
+
end
|
128
|
+
|
129
|
+
context "has an oembed_response and" do
|
130
|
+
setup do
|
131
|
+
@response = @photo.oembed_response
|
132
|
+
end
|
133
|
+
|
134
|
+
context "has required attribute that" do
|
135
|
+
should "be title" do
|
136
|
+
assert @response.title.present?
|
137
|
+
end
|
138
|
+
|
139
|
+
should "be version" do
|
140
|
+
assert @response.version.present?
|
141
|
+
end
|
142
|
+
|
143
|
+
should "be height" do
|
144
|
+
assert @response.height.present?
|
145
|
+
end
|
146
|
+
|
147
|
+
should "be width" do
|
148
|
+
assert @response.width.present?
|
149
|
+
end
|
150
|
+
|
151
|
+
should "be url" do
|
152
|
+
assert @response.url.present?
|
153
|
+
end
|
154
|
+
|
155
|
+
should "be provider_url" do
|
156
|
+
assert @response.provider_url.present?
|
157
|
+
end
|
158
|
+
|
159
|
+
should "be provider_name" do
|
160
|
+
assert @response.provider_name.present?
|
161
|
+
end
|
162
|
+
|
163
|
+
should "be type" do
|
164
|
+
assert @response.type.present?
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "has can have optional attribute that" do
|
169
|
+
should "be author_name" do
|
170
|
+
@photo = FactoryGirl.create(:photo, :author_name => "Snappy")
|
171
|
+
assert @photo.oembed_response.author_name.present?
|
172
|
+
assert_equal "Snappy", @photo.oembed_response.author_name
|
173
|
+
end
|
174
|
+
|
175
|
+
should "be author_url" do
|
176
|
+
@photo = FactoryGirl.create(:photo, :author_url => "http://snapsnap.com")
|
177
|
+
assert @photo.oembed_response.author_url.present?
|
178
|
+
assert_equal "http://snapsnap.com", @photo.oembed_response.author_url
|
179
|
+
end
|
180
|
+
|
181
|
+
should "be thumbnail_url" do
|
182
|
+
@photo = FactoryGirl.create(:photo, :thumbnail_url => "http://snapsnap.com/thumb.jpg")
|
183
|
+
assert @photo.oembed_response.thumbnail_url.present?
|
184
|
+
assert_equal "http://snapsnap.com/thumb.jpg", @photo.oembed_response.thumbnail_url
|
185
|
+
end
|
186
|
+
|
187
|
+
should "be thumbnail_width" do
|
188
|
+
@photo = FactoryGirl.create(:photo, :thumbnail_width => 50)
|
189
|
+
assert @photo.oembed_response.thumbnail_width.present?
|
190
|
+
assert_equal 50, @photo.oembed_response.thumbnail_width
|
191
|
+
end
|
192
|
+
|
193
|
+
should "be thumbnail_height" do
|
194
|
+
@photo = FactoryGirl.create(:photo, :thumbnail_height => 50)
|
195
|
+
assert @photo.oembed_response.thumbnail_height.present?
|
196
|
+
assert_equal 50, @photo.oembed_response.thumbnail_height
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "when returning json" do
|
201
|
+
should "succeed" do
|
202
|
+
assert @response.as_json
|
203
|
+
assert !@response.to_json.to_s.include?(':null')
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "when returning xml" do
|
208
|
+
should "succeed" do
|
209
|
+
assert @response.to_xml
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OembedProviderTest < ActiveSupport::TestCase
|
4
|
+
test "truth" do
|
5
|
+
assert_kind_of Module, OembedProviderEngine
|
6
|
+
end
|
7
|
+
|
8
|
+
context "The OembedProvider object" do
|
9
|
+
should "be able to set and return its provider name" do
|
10
|
+
name = "Media Conglomerate International"
|
11
|
+
OembedProviderEngine::OembedProvider.provider_name = name
|
12
|
+
assert_equal OembedProviderEngine::OembedProvider.provider_name, name
|
13
|
+
end
|
14
|
+
|
15
|
+
should "be able to set and return its provider url" do
|
16
|
+
url = "http://example.com"
|
17
|
+
OembedProviderEngine::OembedProvider.provider_url = url
|
18
|
+
assert_equal OembedProviderEngine::OembedProvider.provider_url, url
|
19
|
+
end
|
20
|
+
|
21
|
+
should "be able to set and return its cache age" do
|
22
|
+
age = "1440"
|
23
|
+
OembedProviderEngine::OembedProvider.cache_age = age
|
24
|
+
assert_equal OembedProviderEngine::OembedProvider.cache_age, age
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return version as 1.0 of oEmbed spec" do
|
28
|
+
assert_equal "1.0", OembedProviderEngine::OembedProvider.version
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have an array of base attribute keys" do
|
32
|
+
base_attributes = [:provider_url,
|
33
|
+
:provider_name,
|
34
|
+
:cache_age,
|
35
|
+
:type,
|
36
|
+
:version]
|
37
|
+
|
38
|
+
assert_equal OembedProviderEngine::OembedProvider.base_attributes, base_attributes
|
39
|
+
end
|
40
|
+
|
41
|
+
should "have an array of optional attribute keys" do
|
42
|
+
optional_attributes = [:title,
|
43
|
+
:author_name,
|
44
|
+
:author_url,
|
45
|
+
:thumbnail_url,
|
46
|
+
:thumbnail_width,
|
47
|
+
:thumbnail_height]
|
48
|
+
|
49
|
+
assert_equal OembedProviderEngine::OembedProvider.optional_attributes, optional_attributes
|
50
|
+
end
|
51
|
+
|
52
|
+
should "have a hash of keyed by oembed type with required attribute keys" do
|
53
|
+
required_attributes = {
|
54
|
+
:photo => [:url, :width, :height],
|
55
|
+
:video => [:html, :width, :height],
|
56
|
+
:link => [],
|
57
|
+
:rich => [:html, :width, :height] }
|
58
|
+
|
59
|
+
assert_equal OembedProviderEngine::OembedProvider.required_attributes, required_attributes
|
60
|
+
end
|
61
|
+
|
62
|
+
should "have a hash of keyed by oembed type photo with required attribute keys" do
|
63
|
+
requires = [:url, :width, :height]
|
64
|
+
assert_equal OembedProviderEngine::OembedProvider.required_attributes[:photo], requires
|
65
|
+
end
|
66
|
+
|
67
|
+
should "have a hash of keyed by oembed type video with required attribute keys" do
|
68
|
+
requires = [:html, :width, :height]
|
69
|
+
assert_equal OembedProviderEngine::OembedProvider.required_attributes[:video], requires
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have a hash of keyed by oembed type link with required attribute keys" do
|
73
|
+
requires = []
|
74
|
+
assert_equal OembedProviderEngine::OembedProvider.required_attributes[:link], requires
|
75
|
+
end
|
76
|
+
|
77
|
+
should "have a hash of keyed by oembed type rich with required attribute keys" do
|
78
|
+
requires = [:html, :width, :height]
|
79
|
+
assert_equal OembedProviderEngine::OembedProvider.required_attributes[:rich], requires
|
80
|
+
end
|
81
|
+
|
82
|
+
context "have an cattr accessor for mapping controllers that aren't tableized version of models, to their corresponding models" do
|
83
|
+
should "be able to set and read controller_model_maps" do
|
84
|
+
assert OembedProviderEngine::OembedProvider.respond_to?(:controller_model_maps)
|
85
|
+
assert_equal Hash.new, OembedProviderEngine::OembedProvider.controller_model_maps
|
86
|
+
test_hash = { :images => 'StillImage' }
|
87
|
+
OembedProviderEngine::OembedProvider.controller_model_maps = test_hash
|
88
|
+
assert_equal test_hash, OembedProviderEngine::OembedProvider.controller_model_maps
|
89
|
+
test_hash[:audio] = 'AudioRecording'
|
90
|
+
OembedProviderEngine::OembedProvider.controller_model_maps[:audio] = 'AudioRecording'
|
91
|
+
assert_equal test_hash, OembedProviderEngine::OembedProvider.controller_model_maps
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be able to answer find_provided_from with provided object based on passed in url" do
|
96
|
+
photo = FactoryGirl.create(:photo)
|
97
|
+
url = "http://example.com/photos/#{photo.id}"
|
98
|
+
|
99
|
+
assert_equal photo, OembedProviderEngine::OembedProvider.find_provided_from(url)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "raise RecordNotFound with non existent photo" do
|
103
|
+
assert_raise ActiveRecord::RecordNotFound do
|
104
|
+
OembedProviderEngine::OembedProvider.find_provided_from("http://example.com/photos/123")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require 'factory_girl_rails'
|
7
|
+
require 'shoulda'
|
8
|
+
require 'nokogiri'
|
9
|
+
require 'capybara/rails'
|
10
|
+
|
11
|
+
module ActionController
|
12
|
+
class IntegrationTest
|
13
|
+
include Capybara::DSL
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Rails.backtrace_cleaner.remove_silencers!
|
18
|
+
|
19
|
+
# Load support files
|
20
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
21
|
+
|
22
|
+
# Load fixtures from the engine
|
23
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
24
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
25
|
+
end
|