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

Modernize #209

Merged
merged 2 commits into from
Jan 5, 2019
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
57 changes: 38 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
language: ruby
sudo: false

cache: bundler

before_install:
- sudo apt-get install -qq graphviz
- gem update --system
- gem install bundler

before_script:
- gem list
- bundle show
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

rvm:
- 2.3.1
- 2.5
- 2.4
- 2.3

gemfile:
- gemfiles/Gemfile.rails-edge
- gemfiles/activerecord-4.1.Gemfile
- gemfiles/activerecord-4.2.Gemfile
- gemfiles/activerecord-5.0.Gemfile
- gemfiles/activerecord-5.1.Gemfile
- gemfiles/activerecord-5.2.Gemfile

matrix:
include:
- rvm: 1.9.3
gemfile: gemfiles/Gemfile.rails-3.x

- rvm: 2.0.0
gemfile: gemfiles/Gemfile.rails-3.x
matrix:
exclude:
# RUBY 2.3
- rvm: 2.3
gemfile: gemfiles/activerecord-5.0.Gemfile

- rvm: 2.0.0
gemfile: gemfiles/Gemfile.rails-4.0
- rvm: 2.3
gemfile: gemfiles/activerecord-5.1.Gemfile

- rvm: 2.3.1
gemfile: gemfiles/Gemfile.rails-4.0
- rvm: 2.3
gemfile: gemfiles/activerecord-5.2.Gemfile

- rvm: 2.3.1
gemfile: gemfiles/Gemfile.rails-5.0
allow_failures:
- gemfile: gemfiles/Gemfile.rails-5.0
- gemfile: gemfiles/Gemfile.rails-edge
# RUBY 2.4
- rvm: 2.4
gemfile: gemfiles/activerecord-4.1.Gemfile

# RUBY 2.5
- rvm: 2.5
gemfile: gemfiles/activerecord-4.1.Gemfile
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
source "http://rubygems.org"

gemspec

group :test do
gem 'simplecov'
end
7 changes: 6 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[![Build Status](https://travis-ci.org/geekq/workflow.png?branch=master)](https://travis-ci.org/geekq/workflow) Tested with [different Ruby and Rails versions](https://travis-ci.org/geekq/workflow)
[![Version ](https://img.shields.io/gem/v/workflow.svg?maxAge=2592000)](https://rubygems.org/gems/workflow)
[![Build Status ](https://travis-ci.org/geekq/workflow.svg)](https://travis-ci.org/geekq/workflow)
[![Code Climate ](https://codeclimate.com/github/geekq/workflow/badges/gpa.svg)](https://codeclimate.com/github/geekq/workflow)
[![Test Coverage](https://codeclimate.com/github/geekq/workflow/badges/coverage.svg)](https://codeclimate.com/github/geekq/workflow/coverage)

# Workflow

Note: you can find documentation for specific workflow rubygem versions
at http://rubygems.org/gems/workflow : select a version (optional,
Expand Down
18 changes: 7 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
require 'rubygems'
require 'rake/testtask'
require "bundler/gem_tasks"
require "rake/testtask"
require 'rdoc/task'

require 'bundler'
Bundler.setup

task :default => [:test]

require 'rake'
Rake::TestTask.new do |t|
t.libs << 'test'
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.verbose = true
t.warning = true
t.test_files = FileList['test/*_test.rb'] + FileList['test/new_versions/*_test.rb']
t.test_files = FileList["test/**/*_test.rb"]
end

Rake::TestTask.new do |t|
Expand All @@ -28,3 +23,4 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << "-S"
end

task :default => :test
11 changes: 0 additions & 11 deletions gemfiles/Gemfile.rails-3.x

This file was deleted.

14 changes: 0 additions & 14 deletions gemfiles/Gemfile.rails-4.0

This file was deleted.

13 changes: 0 additions & 13 deletions gemfiles/Gemfile.rails-5.0

This file was deleted.

13 changes: 0 additions & 13 deletions gemfiles/Gemfile.rails-edge

This file was deleted.

5 changes: 5 additions & 0 deletions gemfiles/activerecord-4.1.Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")

gem 'activerecord', '~> 4.1.0'
gem 'protected_attributes'
gem 'pg', '~> 0.20.0'
5 changes: 5 additions & 0 deletions gemfiles/activerecord-4.2.Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")

gem 'activerecord', '~> 4.2.0'
gem 'protected_attributes'
gem 'pg', '~> 0.20.0'
3 changes: 3 additions & 0 deletions gemfiles/activerecord-5.0.Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")

gem 'activerecord', '~> 5.0.0'
3 changes: 3 additions & 0 deletions gemfiles/activerecord-5.1.Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")

gem 'activerecord', '~> 5.1.0'
3 changes: 3 additions & 0 deletions gemfiles/activerecord-5.2.Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")

gem 'activerecord', '~> 5.2.0'
8 changes: 8 additions & 0 deletions lib/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
require 'workflow/adapters/active_record'
require 'workflow/adapters/remodel'

begin
require 'ruby-graphviz'
require 'active_support/inflector'
require 'workflow/draw'
rescue LoadError => e
$stderr.puts "Could not load the ruby-graphiz or active_support gems for rendering: #{e.message}"
end

# See also README.markdown for documentation
module Workflow
module ClassMethods
Expand Down
18 changes: 3 additions & 15 deletions lib/workflow/draw.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
begin
require 'rubygems'

gem 'ruby-graphviz', '~> 1.0.0'
gem 'activesupport'

require 'graphviz'
require 'active_support/inflector'
rescue LoadError => e
$stderr.puts "Could not load the ruby-graphiz or active_support gems for rendering: #{e.message}"
end

module Workflow
module Draw

Expand Down Expand Up @@ -48,9 +36,9 @@ def self.workflow_diagram(klass, options={})
:ratio => "fill",
:format => 'png',
:font => 'Helvetica'
}.merge options
}.merge options

graph = ::GraphViz.new('G', :rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB', :ratio => options[:ratio])
graph = ::GraphViz.new('G', :rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB', :ratio => options[:ratio])

# Add nodes
klass.workflow_spec.states.each do |_, state|
Expand All @@ -66,7 +54,7 @@ def self.workflow_diagram(klass, options={})
# Generate the graph
filename = File.join(options[:path], "#{options[:name]}.#{options[:format]}")

graph.output options[:format] => "'#{filename}'"
graph.output options[:format] => filename

puts "
Please run the following to open the generated file:
Expand Down
9 changes: 6 additions & 3 deletions test/advanced_hooks_and_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class Article < ActiveRecord::Base
fields_to_validate = meta[:validates_presence_of]
if fields_to_validate
validations = Proc.new {
errors.add_on_blank(fields_to_validate) if fields_to_validate
Array(fields_to_validate).each do |attribute|
value = self.send(:read_attribute_for_validation, attribute)
errors.add(attribute, :blank) if value.blank?
end
}
end

Expand Down Expand Up @@ -88,7 +91,7 @@ def assert_state(title, expected_state, klass = Order)

test 'deny transition from new to accepted because of the missing presence of the body' do
a = Article.find_by_title('new1');
assert_raise Workflow::TransitionHalted do
assert_raises Workflow::TransitionHalted do
a.accept!
end
assert_state 'new1', 'new', Article
Expand All @@ -109,7 +112,7 @@ def assert_state(title, expected_state, klass = Order)

test 'deny transition from accepted to blamed because of no blame_reason' do
a = Article.find_by_title('accepted1');
assert_raise Workflow::TransitionHalted do
assert_raises Workflow::TransitionHalted do
assert a.blame!
end
assert_state 'accepted1', 'accepted', Article
Expand Down
2 changes: 0 additions & 2 deletions test/attr_protected_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class AttrProtectedTestOrder < ActiveRecord::Base
state :shipped
end

attr_accessible :title # protecting all the other attributes

end

AttrProtectedTestOrder.logger = Logger.new(STDOUT) # active_record 2.3 expects a logger instance
Expand Down
2 changes: 1 addition & 1 deletion test/before_transition_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), 'test_helper')
require 'workflow'

class BeforeTransitionTest < Test::Unit::TestCase
class BeforeTransitionTest < Minitest::Test
class MyFlow
attr_reader :history
def initialize
Expand Down
2 changes: 1 addition & 1 deletion test/couchtiny_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def persist_workflow_state(new_value)
end


class CouchtinyExample < Test::Unit::TestCase
class CouchtinyExample < Minitest::Test

def setup
db = CouchTiny::Database.url("http://127.0.0.1:5984/test-workflow")
Expand Down
2 changes: 1 addition & 1 deletion test/inheritance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Cat < Animal

animal.birth!

assert_raise NoMethodError, 'Methods defined by the old workflow spec should have be gone away' do
assert_raises NoMethodError, 'Methods defined by the old workflow spec should have be gone away' do
cat.birth!
end

Expand Down
16 changes: 8 additions & 8 deletions test/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def assert_state(title, expected_state, klass = Order)
end
end
end
assert_not_nil c.workflow_spec.on_transition_proc
assert nil != c.workflow_spec.on_transition_proc
c.new.increment!
end

Expand Down Expand Up @@ -246,7 +246,7 @@ def assert_state(title, expected_state, klass = Order)

test 'correct exception for event, that is not allowed in current state' do
o = assert_state 'some order', 'accepted'
assert_raise Workflow::NoTransitionAllowed do
assert_raises Workflow::NoTransitionAllowed do
o.accept!
end
end
Expand Down Expand Up @@ -387,7 +387,7 @@ class Problem
end
end
end
assert_raise Workflow::WorkflowError do
assert_raises Workflow::WorkflowError do
Problem.new.solve!
end
end
Expand Down Expand Up @@ -496,7 +496,7 @@ def reject(reason)

article = article_class.new
assert article.new?
assert_raise Workflow::TransitionHalted do
assert_raises Workflow::TransitionHalted do
article.reject! 'Too funny'
end
assert_nil article.too_far
Expand Down Expand Up @@ -577,11 +577,11 @@ def sufficient_battery_level?
end

def capture_streams
old_stdout = $stdout
$stdout = captured_stdout = StringIO.new
old_stdout, $stdout = $stdout, StringIO.new
yield
$stdout = old_stdout
captured_stdout
$stdout
ensure
captured, $stdout = $stdout, old_stdout
end

end
Expand Down
4 changes: 2 additions & 2 deletions test/new_versions/compare_states_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ComparableStatesOrder
end
end

class CompareStatesTest < Test::Unit::TestCase
class CompareStatesTest < Minitest::Test

test 'compare states' do
o = ComparableStatesOrder.new
Expand All @@ -24,7 +24,7 @@ class CompareStatesTest < Test::Unit::TestCase
assert o.current_state == :accepted
assert o.current_state < :shipped
assert o.current_state > :submitted
assert_raise ArgumentError do
assert_raises ArgumentError do
o.current_state > :unknown
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/new_versions/persistence_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class PersistenceTestOrder < ActiveRecord::Base
state :shipped
end

attr_accessible :title # protecting all the other attributes

end

PersistenceTestOrder.logger = Logger.new(STDOUT) # active_record 2.3 expects a logger instance
Expand Down
Loading