Commit e43f1aea
Changed files (4)
app
helpers
views
creations
shared
spec
helpers
app/helpers/application_helper.rb
@@ -16,4 +16,12 @@ module ApplicationHelper
"#{title} - CakeSide"
end
end
+
+ def disqus_auth(user = current_user)
+ data = { id: user.id, username: user.username, email: user.email }.to_json
+ message = Base64.encode64(data).gsub("\n", "")
+ timestamp = Time.now.to_i
+ signature = OpenSSL::HMAC.hexdigest('sha1', ENV['DISQUS_SECRET_KEY'], "#{message} #{timestamp}")
+ "#{message} #{signature} #{timestamp}"
+ end
end
app/views/creations/show.html.erb
@@ -134,3 +134,5 @@ $(function() {
</div>
<% end %>
</div>
+
+<%= render :partial => "disqus", :locals => { :id => "c-#{@creation.id}" } %>
spec/helpers/application_helper_spec.rb
@@ -0,0 +1,22 @@
+require "spec_helper"
+
+describe ApplicationHelper do
+ describe :disqus_auth do
+ let(:user) { OpenStruct.new(id: 1, username: 'blah', email: 'test@fairgoods.com') }
+
+ before :each do
+ data = { id: user.id, username: user.username, email: user.email }.to_json
+ message = Base64.encode64(data).gsub("\n", "")
+ timestamp = Time.now.to_i
+ secret = ENV['DISQUS_SECRET_KEY'] = 'secret'
+ signature = OpenSSL::HMAC.hexdigest('sha1', secret, "#{message} #{timestamp}")
+ @expected = "#{message} #{signature} #{timestamp}"
+ end
+
+ it "should generate a single sign on token" do
+ result = helper.disqus_auth(user)
+ result.should_not be_nil
+ result.should == @expected
+ end
+ end
+end