Skip to content

Commit

Permalink
Merge pull request #2 from chrissiedeist/bugfix_v1.0.1
Browse files Browse the repository at this point in the history
Bugfix - Repaired tests and replaced swath of missing code
  • Loading branch information
raymondberg committed Sep 23, 2015
2 parents 7c6885f + 33e62cf commit c3adef6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 15 deletions.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

task :default => "spec:integration"

desc "Run tests"
RSpec::Core::RakeTask.new("spec:integration") do |t|
t.pattern = "spec/*.rb"
end
36 changes: 23 additions & 13 deletions lib/github_to_trello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,42 @@


class GithubToTrello
def initialize(public_key, token, board_id, repo_name)
@github_gateway = GithubGateway.new(repo_name)
@trello_gateway = TrelloGateway.new(public_key,
token,
board_id,
repo_name)
def initialize(options)
[:public_key, :token, :board_id, :repo_name].each do |required_field|
_raise_argument_error(required_field) unless options[required_field]
end

@github_gateway = GithubGateway.new(options[:repo_name])
@trello_gateway = TrelloGateway.new(
{
:inbox_name => options[:repo_name],
}.merge(options)
)
end

def update
@github_gateway.issues.each do |issue|
@trello_gateway.create_or_update_card(issue)
end
end

def _raise_argument_error(field)
raise ArgumentError, "Argument '#{field}' is required yet missing"
end
end

# Example usage with dotenv gem and .env file
#
# if __FILE__ == $PROGRAM_NAME
# public_key = ENV["PUBLIC_KEY"]
# token = ENV["TOKEN"]
# board_id = ENV["BOARD_ID"]
# repos = ENV["REPOS"].split(",")
#
# repos.each do |repo|
# ENV["REPOS"].split(",").each do |repo|
# puts "Updating repo: #{repo}"
# GithubToTrello.new(public_key, token, board_id, repo).update
#
# GithubToTrello.new(
# :public_key => ENV["PUBLIC_KEY"],
# :token => ENV["TOKEN"],
# :board_id => ENV["BOARD_ID"],
# :repo_name => repo,
# ).update
# end
# end

2 changes: 1 addition & 1 deletion lib/github_to_trello/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GithubToTrello
VERSION = "1.0.0"
VERSION = "1.0.1"
end
72 changes: 72 additions & 0 deletions spec/github_to_trello_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'rspec'
require_relative '../lib/github_to_trello'

describe GithubToTrello do
before(:all) do
@options = {
:public_key => "abcdef",
:token => "ghilmnopqrstuvwxyz",
:board_id => "123456",
:repo_name => "chrissiedeist/django_blog",
:inbox_name => "django_blog",
}
end

describe "new" do
it "sets up github and trello gateways" do
expect(GithubGateway).to receive(:new).with(@options[:repo_name])
expect(TrelloGateway).to receive(:new).with(@options)

gateway = GithubToTrello.new(@options)
end

it "defaults to repository name when inbox isn't provided" do
allow(GithubGateway).to receive(:new).with(@options[:repo_name])

@options.delete(:inbox_name)
expected_options = {
:inbox_name => @options[:repo_name],
}.merge(@options)

expect(TrelloGateway).to receive(:new).with(expected_options)

gateway = GithubToTrello.new(@options)
end

it "raises an error if any mandatory fields aren't passed" do
required_fields = [:public_key, :token, :board_id, :repo_name]

(1..3).each do |field_count|
required_fields.combination(field_count).to_a.each do |field_combo|
bad_options = {}
field_combo.each do |field|
bad_options[field] = @options[field]
end

expect{ GithubToTrello.new(bad_options)}.to raise_error(ArgumentError)
end
end
end
end

describe "update" do
it "iterates over issues" do
issues = ["first", "second", "third"]
fake_github_gateway = fake_trello_gateway = double()


allow(GithubGateway).to receive(:new).and_return(fake_github_gateway)
allow(TrelloGateway).to receive(:new).and_return(fake_trello_gateway)

gateway = GithubToTrello.new(@options)

expect(fake_github_gateway).to receive(:issues).and_return(issues)

issues.each do |issue|
expect(fake_trello_gateway).to receive(:create_or_update_card).with(issue)
end

gateway.update
end
end
end
2 changes: 1 addition & 1 deletion spec/trello_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:public_key => "56acdaa7404ebcc8bbaffab18428d4d2",
:token => "08f4481d00aba0091592ad9e0ce7e025ac9e238ead31852fe4a75270fbd562e9",
:board_id => "5jGWvKui",
:repo_name => "django_blog",
:inbox_name => "django_blog",
)

@issue = double(:issue,
Expand Down

0 comments on commit c3adef6

Please sign in to comment.