github_concern 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -24,7 +24,7 @@ gem 'github_concern', :git => 'http://github.com/adamgamble/github_concern.git'
24
24
  bundle install
25
25
 
26
26
  Now github\_concern is available to your application. Next, add a service hook
27
- to your github repo that posts to http://your\_url/github\_integration
27
+ to your github repo that posts to http://your\_url/github\_integration?token=some_unique_token
28
28
 
29
29
  Add this to config/initializers/github\_concern.rb:
30
30
 
@@ -32,6 +32,7 @@ Add this to config/initializers/github\_concern.rb:
32
32
  GithubConcern::Engine.config do |gc|
33
33
  gc.user_lambda = lambda {|email| User.find_by_email email}
34
34
  gc.user_class = User
35
+ gc.token = "some_unique_token"
35
36
  end
36
37
  ```
37
38
 
@@ -1,5 +1,6 @@
1
1
  class GithubController < ApplicationController
2
2
  def payload
3
+ render :nothing => true, :status => 404 and return unless params.keys.include?("token") && params["token"] == GithubConcern::Engine.token
3
4
  render :nothing => true, :status => 500 and return unless params["payload"]
4
5
  GitPush.create(:payload => JSON.parse(params["payload"]))
5
6
  render :nothing => true, :status => 200
@@ -3,6 +3,7 @@ module GithubConcern
3
3
  class Engine < Rails::Engine
4
4
  @@github_concerns = {}
5
5
  @@callback_lambdas = []
6
+ @@token = ""
6
7
 
7
8
  def self.config
8
9
  yield(self)
@@ -26,6 +27,14 @@ module GithubConcern
26
27
  end
27
28
  end
28
29
 
30
+ def self.token= _token
31
+ @@token = _token
32
+ end
33
+
34
+ def self.token
35
+ @@token
36
+ end
37
+
29
38
  def self.user_lambda= find_user_lambda
30
39
  @@user_lambda = find_user_lambda
31
40
  end
@@ -1,3 +1,3 @@
1
1
  module GithubConcern
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -3,14 +3,25 @@ require 'spec_helper'
3
3
  describe GithubController do
4
4
  describe "POST payload" do
5
5
  it "returns 500 when not sending a payload" do
6
- post :payload
6
+ post :payload, :token => GithubConcern::Engine.token
7
7
  response.code.should == "500"
8
8
  end
9
9
 
10
- describe "when sending a valid payload" do
10
+ describe "when sending a valid payload with an invalid token" do
11
11
  before(:each) do
12
12
  payload = valid_payload_hash.to_json
13
- post :payload, :payload => payload
13
+ post :payload, :payload => payload, :token => "my_token"
14
+ end
15
+
16
+ it "should return a 404" do
17
+ response.code.should == "404"
18
+ end
19
+ end
20
+
21
+ describe "when sending a valid payload and a valid token" do
22
+ before(:each) do
23
+ payload = valid_payload_hash.to_json
24
+ post :payload, :payload => payload, :token => GithubConcern::Engine.token
14
25
  end
15
26
 
16
27
  it "returns 200 when sending a valid payload" do
@@ -1,6 +1,7 @@
1
1
  GithubConcern::Engine.config do |gc|
2
2
  gc.user_lambda = lambda {|email| User.find_by_email email}
3
3
  gc.user_class = User
4
+ gc.token = "my_github_token"
4
5
  end
5
6
 
6
7
  Module.constants.select do |constant_name|