Skip to content
Browse files

fixing bug for when data is missing

  • Loading branch information...
1 parent f989ede commit 1fafa12ecea259b4fe1c496c5e22d79c1d816a2e @beaucollins committed Sep 9, 2010
View
15 lib/power_reviews/review_data.rb
@@ -5,11 +5,21 @@ module PowerReviews
class ReviewData
+ class MissingData < StandardError; end;
+
+ DATA_FILES = ['review_data_complete', 'review_data_summary']
+
class << self
# retrieve the summary data for the given page_id
def summary(page_id)
document.summary(page_id)
+ rescue MissingData
+ nil
+ end
+
+ def reload!
+ @document = nil
end
protected
@@ -51,11 +61,12 @@ def read_document(name)
def xml_documents
return @files unless @files.nil?
files = {}
-
Find.find(@search_path) do |path|
bn = File.basename(path, '.xml')
- files[bn] = path if ['review_data_complete', 'review_data_summary'].include?(bn)
+ files[bn] = path if DATA_FILES.include?(bn)
end
+ missing = DATA_FILES.select { |f| files[f].blank? }
+ raise MissingData, "missing Power Reviews xml: #{missing.collect {|f| f + ".xml"}.join(', ')}" unless missing.empty?
@files = files
@files
end
View
2 lib/power_reviews/sync.rb
@@ -49,7 +49,7 @@ def start
end
def configure
- @config ||= YAML::load(File.open("#{RAILS_ROOT}/config/power_reviews.yml"))[Rails.environment] || {}
+ @config ||= YAML::load(File.open("#{RAILS_ROOT}/config/power_reviews.yml"))[Rails.env] || {}
end
end
View
5 lib/power_reviews/view_helpers.rb
@@ -10,7 +10,7 @@ def power_reviews_hreview(page_id, &blk)
if block_given?
yield summary unless summary.nil?
- else summary.nil?
+ elsif !summary.nil?
<<-review
<div class='hreview-aggregate'>
@@ -24,7 +24,8 @@ def power_reviews_hreview(page_id, &blk)
<span class="count">#{summary.reviews}</span> user reviews.
</div>
review
-
+ else
+ ''
end
end
View
2 power_reviews.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{power_reviews}
- s.version = "0.3.0"
+ s.version = "0.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Beau Collins"]
View
20 test/power_reviews/review_data_test.rb
@@ -18,4 +18,24 @@ class ReviewDataTest < ActiveSupport::TestCase
end
+ context "with missing xml" do
+
+ setup do
+ PowerReviews::Config.review_data_path='/var/tmp'
+ PowerReviews::ReviewData.reload!
+ end
+
+ should "raise error when no review data" do
+ @data = PowerReviews::ReviewData.new(nil)
+ assert_raises PowerReviews::ReviewData::MissingData do
+ @data.summary('shadow')
+ end
+ end
+
+ should "return nil data" do
+ assert_nil PowerReviews::ReviewData.summary('shadow')
+ end
+
+ end
+
end
View
5 test/power_reviews/view_helpers_test.rb
@@ -12,6 +12,11 @@ def controller
@controller ||= FakeController.new
end
+ setup do
+ PowerReviews::Config.review_data_path='test/fixtures/rawdata'
+ PowerReviews::ReviewData.reload!
+ end
+
should "have hReview helper" do
assert controller.power_reviews_hreview('shadow') =~ %r{<span class="fn">Shadow</span>}

0 comments on commit 1fafa12

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