mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Adding spec, removing auth_check
This commit is contained in:
parent
267ca18a03
commit
765151093d
3 changed files with 39 additions and 15 deletions
|
@ -22,7 +22,6 @@ class ApplicationController < ActionController::Base
|
|||
return unless current_user
|
||||
twitter_oauth_check
|
||||
basecamp_auth_check
|
||||
tumblr_oauth_check
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -41,13 +40,4 @@ class ApplicationController < ActionController::Base
|
|||
@basecamp_agent = current_user.agents.where(type: 'Agents::BasecampAgent').first
|
||||
end
|
||||
end
|
||||
|
||||
def tumblr_oauth_check
|
||||
if ENV['TUMBLR_OAUTH_KEY'].blank? || ENV['TUMBLR_OAUTH_SECRET'].blank?
|
||||
if @tumblr_agent = current_user.agents.where("type like 'Agents::Tumblr%'").first
|
||||
@tumblr_oauth_key = @tumblr_agent.options['consumer_key'].presence || @tumblr_agent.credential('tumblr_consumer_key')
|
||||
@tumblr_oauth_secret = @tumblr_agent.options['consumer_secret'].presence || @tumblr_agent.credential('tumblr_consumer_secret')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,7 +101,6 @@ module Agents
|
|||
options = interpolated(event)['options']
|
||||
begin
|
||||
post = publish_post(blog_name, post_type, options)
|
||||
puts "[POST] "+JSON.pretty_generate(post)
|
||||
create_event :payload => {
|
||||
'success' => true,
|
||||
'published_post' => "["+blog_name+"] "+post_type,
|
||||
|
@ -113,10 +112,7 @@ module Agents
|
|||
end
|
||||
end
|
||||
|
||||
def publish_post(blog_name, post_type, options)
|
||||
puts "[BLOG NAME] "+blog_name
|
||||
puts "[POST_TYPE] "+post_type
|
||||
|
||||
def publish_post(blog_name, post_type, options)
|
||||
options_obj = {
|
||||
:state => options['state'],
|
||||
:tags => options['tags'],
|
||||
|
|
38
spec/models/agents/tumblr_publish_agent_spec.rb
Normal file
38
spec/models/agents/tumblr_publish_agent_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Agents::TumblrPublishAgent do
|
||||
before do
|
||||
@opts = {
|
||||
:blog_name => "huginnbot.tumblr.com",
|
||||
:post_type => "text",
|
||||
:expected_update_period_in_days => "2",
|
||||
:options => {
|
||||
:title => "{{title}}",
|
||||
:body => "{{body}}",
|
||||
},
|
||||
}
|
||||
|
||||
@checker = Agents::TumblrPublishAgent.new(:name => "HuginnBot", :options => @opts)
|
||||
@checker.service = services(:generic)
|
||||
@checker.user = users(:bob)
|
||||
@checker.save!
|
||||
|
||||
@event = Event.new
|
||||
@event.agent = agents(:bob_weather_agent)
|
||||
@event.payload = { :title => "Gonna rain...", :body => 'San Francisco is gonna get wet' }
|
||||
@event.save!
|
||||
|
||||
stub.any_instance_of(Agents::TumblrPublishAgent).tumblr {
|
||||
stub!.text(anything, anything) { { "id" => "5" } }
|
||||
}
|
||||
end
|
||||
|
||||
describe '#receive' do
|
||||
it 'should publish any payload it receives' do
|
||||
Agents::TumblrPublishAgent.async_receive(@checker.id, [@event.id])
|
||||
@checker.events.count.should eq(1)
|
||||
@checker.events.first.payload['post_id'].should eq('5')
|
||||
@checker.events.first.payload['published_post'].should eq('[huginnbot.tumblr.com] text')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue