Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - Repaired tests and replaced swath of missing code #2

Merged
merged 1 commit into from
Sep 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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