Skip to content
Browse files

Fix errors in the Atom feed

* Add platform in title if needed
* Fix undefined entry element: platform validation error
* Fix link url to point to the specific rubygem version
* Fix multiple entries with the same id validation error
* Fix missing author element: name validation error
* Fix summary should not be blank validation warning
* Fix double escaped version summary

Signed-off-by: Nick Quaranto <nick@quaran.to>
  • Loading branch information...
1 parent abe335a commit 905da6be7a1d5473c89625823f87bba54c81588f @cgriego cgriego committed with qrush Oct 10, 2010
View
11 app/views/versions/feed.atom.builder
@@ -13,13 +13,12 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
@versions.each do |version|
xml.entry do
- xml.title version.to_title
- xml.platform version.platform
- xml.link "rel" => "alternate", "href" => rubygem_url(version.rubygem, version.slug)
- xml.id rubygem_url(version.rubygem, :version => version.number)
+ xml.title "#{version.to_title}#{" " + version.platform if version.platformed?}"
+ xml.link "rel" => "alternate", "href" => rubygem_version_url(version.rubygem, version.slug)
+ xml.id rubygem_version_url(version.rubygem, version.slug)
xml.updated version.created_at.strftime("%Y-%m-%dT%H:%M:%SZ")
- xml.author { h(version.authors) }
- xml.summary h(version.summary)
+ xml.author {|author| author.name h(version.authors) }
+ xml.summary version.summary if version.summary?
xml.content "type" => "html" do
xml.text! h(version.description)
end
View
28 test/functional/dashboards_controller_test.rb
@@ -32,10 +32,10 @@ class DashboardsControllerTest < ActionController::TestCase
context "On GET to show as an atom feed" do
setup do
- @subscribed_versions = (1..3).map { |n| Factory(:version, :created_at => n.hours.ago) }
+ @subscribed_versions = (1..2).map { |n| Factory(:version, :created_at => n.hours.ago) }
+ # just to make sure one has a different platform and a summary
+ @subscribed_versions << Factory(:version, :created_at => 3.hours.ago, :platform => "win32", :summary => "&")
@subscribed_versions.each { |v| Factory(:subscription, :rubygem => v.rubygem, :user => @user)}
- # just to make sure one has a different platform
- @subscribed_versions.last.update_attributes(:platform => "win32")
@unsubscribed_versions = (1..3).map { |n| Factory(:version, :created_at => n.hours.ago) }
@request.env["Authorization"] = @user.api_key
@@ -44,14 +44,30 @@ class DashboardsControllerTest < ActionController::TestCase
should respond_with :success
should render_template 'versions/feed'
- should "render posts with titles and platform-specific links of all subscribed versions" do
+
+ should "render posts with platform-specific titles and links of all subscribed versions" do
+ @subscribed_versions.each do |v|
+ assert_select "entry > title", :count => 1, :text => (v.platformed? ? "#{v.to_title} #{v.platform}" : v.to_title)
+ assert_select "entry > link[href='#{rubygem_version_url(v.rubygem, v.slug)}']", :count => 1
+ assert_select "entry > id", :count => 1, :text => rubygem_version_url(v.rubygem, v.slug)
+ end
+ end
+
+ should "render valid entry authors" do
+ @subscribed_versions.each do |v|
+ assert_select "entry > author > name", :text => v.authors
+ end
+ end
+
+ should "render entry summaries only for versions with summaries" do
+ assert_select "entry > summary", :count => @subscribed_versions.select {|v| v.summary? }.size
@subscribed_versions.each do |v|
- assert_contain v.to_title
- assert_have_selector "link[href='#{rubygem_url(v.rubygem, v.slug)}']"
+ assert_select "entry > summary", :text => ERB::Util.h(v.summary) if v.summary?
end
end
should "not render posts for versions the user isn't subscribed to" do
+ assert_select "entry", @subscribed_versions.size
@unsubscribed_versions.each do |v|
assert_does_not_contain @response.body, v.to_title
end
View
27 test/functional/rubygems_controller_test.rb
@@ -179,18 +179,33 @@ class RubygemsControllerTest < ActionController::TestCase
context "On GET to index as an atom feed" do
setup do
- @versions = (1..3).map { |n| Factory(:version, :created_at => n.hours.ago) }
- # just to make sure one has a different platform
- @versions.last.update_attributes(:platform => "win32")
+ @versions = (1..2).map { |n| Factory(:version, :created_at => n.hours.ago) }
+ # just to make sure one has a different platform and a summary
+ @versions << Factory(:version, :created_at => 3.hours.ago, :platform => "win32", :summary => "&")
get :index, :format => "atom"
end
should respond_with :success
should assign_to(:versions) { @versions }
- should "render posts with titles and platform-specific links" do
+
+ should "render posts with platform-specific titles and links of all subscribed versions" do
+ @versions.each do |v|
+ assert_select "entry > title", :count => 1, :text => (v.platformed? ? "#{v.to_title} #{v.platform}" : v.to_title)
+ assert_select "entry > link[href='#{rubygem_version_url(v.rubygem, v.slug)}']", :count => 1
+ assert_select "entry > id", :count => 1, :text => rubygem_version_url(v.rubygem, v.slug)
+ end
+ end
+
+ should "render valid entry authors" do
+ @versions.each do |v|
+ assert_select "entry > author > name", :text => v.authors
+ end
+ end
+
+ should "render entry summaries only for versions with summaries" do
+ assert_select "entry > summary", :count => @versions.select {|v| v.summary? }.size
@versions.each do |v|
- assert_contain v.to_title
- assert_have_selector "link[href='#{rubygem_url(v.rubygem, v.slug)}']"
+ assert_select "entry > summary", :text => ERB::Util.h(v.summary) if v.summary?
end
end
end

0 comments on commit 905da6b

Please sign in to comment.
Something went wrong with that request. Please try again.