Skip to content

Commit

Permalink
Starting add the push request to Pushme
Browse files Browse the repository at this point in the history
  • Loading branch information
shingara committed May 11, 2010
1 parent 39f4cf0 commit ea13254
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ gem 'rails3-generators'
gem 'inherited_resources', '1.1.2'
gem 'cancan'
gem 'octopussy'
gem 'rest-client', :require => 'rest_client'

group :test do
gem "rspec-rails", ">= 2.0.0.beta.8"
gem 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl.git', :branch => 'rails3'
gem 'randexp'
gem 'webmock'
end


Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class User
before_create :fetch_repo_watched

before_save :update_atom_feeds
after_save :push_atom_feeds

def update_github_data!
fetch_following
Expand Down Expand Up @@ -73,4 +74,11 @@ def update_atom_feeds
end
end

def push_atom_feeds
self.atom_feeds.each do |atom|
p atom
RestClient.post(AppConfig.pushme_host, :push => {:feed_url => atom, :feed_type => 'atom', :pusher => {:push_type => 'post_http', :options => {:url => "#{AppConfig.host}/atom/callback"}}})
end
end

end
8 changes: 8 additions & 0 deletions config/initializers/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'ostruct'
require 'yaml'
file = Rails.root.join('config/mygithub.yml')
if File.exist?(file)
AppConfig = OpenStruct.new(YAML.load_file(Rails.root.join('config/mygithub.yml'))[Rails.env])
else
raise ArgumentError.new('you need define your mygithub.yml file')
end
6 changes: 6 additions & 0 deletions config/mygithub-sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
development:
pushme_host: http://localhost:3001/
production:
pushme_host: http://pushme.com/
test:
pushme_host: http://localhost:3001/
13 changes: 13 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,17 @@
end
end

describe '#after_save' do
include WebMock

it 'should post subscribe to pushme about all coders watch by user' do
Octopussy.should_receive(:following).with('shingara').and_return(['antires', 'dhh'])
Octopussy.should_receive(:watched).with('shingara').and_return([])
user = Factory(:user, :github_login => 'shingara')
WebMock.should have_requested(:post, 'http://localhost:3001').with(:push => {:feed_url => 'http://github.com/antires.atom', :feed_type => 'atom', :pusher => {:push_type => 'post_http', :options => {:url => 'http://'}}})
WebMock.should have_requested(:post, 'http://localhost:3001').with(:push => {:feed_url => 'http://github.com/dhh.atom', :feed_type => 'atom', :pusher => {:push_type => 'post_http', :options => {:url => 'http://'}}})
end
it 'should post subscribe to pushme about all repositories watch by user'
end

end
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
require 'rspec/rails'
require 'webmock/adapters/rspec/request_pattern_matcher'
require 'webmock/adapters/rspec/webmock_matcher'
require 'webmock/adapters/rspec/matchers'


# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Expand All @@ -18,18 +22,30 @@
# config.mock_with :rr
config.mock_with :rspec

config.include WebMock::Matchers

# If you'd prefer not to run each of your examples within a transaction,
# uncomment the following line.
# config.use_transactional_examples = false
config.before(:each) do
Octopussy.stub!(:user).and_return({:name => 'ok'})
Octopussy.stub!(:following).and_return(['foo', 'bar'])
Octopussy.stub!(:watched).and_return(['foo', 'bar'])
WebMock.reset_webmock
WebMock.stub_request(:post, 'localhost:3001')
end
config.before(:all) do

Mongoid.master.collections.each(&:drop)
end
end

require 'factories'
#require 'webmock/rspec'

module WebMock
def assertion_failure(message)
raise Spec::Expectations::ExpectationNotMetError.new(message)
end
end

0 comments on commit ea13254

Please sign in to comment.