Skip to content

Commit

Permalink
fix missing disqus_identifier, add disqus spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Dec 8, 2012
1 parent ace09f3 commit 2ef8fa8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/awestruct/extensions/disqus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def disqus_comments_count()
}
end

private

def resolve_disqus_identifier()
self.disqus_identifier ? self.disqus_identifier : Digest::SHA1.hexdigest(self.date.strftime('%Y-%m-%d-') + self.slug)
end
Expand Down
42 changes: 42 additions & 0 deletions spec/disqus_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'awestruct/page'
require 'awestruct/extensions/disqus'

describe Awestruct::Extensions::Disqus do

before :all do
@site = Awestruct::AStruct.new :encoding=>false, :disqus=>'spec', :base_url=>'http://example.org'
@disqus = Awestruct::Extensions::Disqus.new
end

before :each do
@page = Awestruct::Page.new @site
@page.date = Time.utc(2012,12,8)
@page.slug = 'spec-post'
@page.url = '/posts/2012/12/08/spec-post/'
@site.pages = [@page]
@disqus.execute(@site)
end

it "should assign the disqus short name" do
@page.disqus_comments().should match(/var disqus_shortname = '#{@site.disqus}';/)
@page.disqus_comments_count().should match(/var disqus_shortname = '#{@site.disqus}';/)
end

it "should generate an identifier if necessary when id generation is enabled" do
@site.disqus_generate_id = true
@page.disqus_comments().should match(/var disqus_identifier = "12bb52d0776930e01e9a410fd14f13382778e449";/)
@page.disqus_comments_link().should match(/ data-disqus-identifier="12bb52d0776930e01e9a410fd14f13382778e449"/)
end

it "should use the identifier specified in the page" do
@page.disqus_identifier = @page.slug
@page.disqus_comments().should match(/var disqus_identifier = "#{@page.disqus_identifier}";/)
@page.disqus_comments_link().should match(/ data-disqus-identifier="#{@page.disqus_identifier}"/)
end

it "should have a null identifier if no identifier is specified and id generation is disabled" do
@page.disqus_comments().should match(/var disqus_identifier = null;/)
@page.disqus_comments_link().should_not match(/ data-disqus-identifier=/)
end

end

0 comments on commit 2ef8fa8

Please sign in to comment.