Sha256: 8977886ccc2145f2c49427fdc26f915e588437f25b4528e5ffdeac132549ce40

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')
require 'couchtiny'
require 'couchtiny/document'
require 'workflow'

class User < CouchTiny::Document
  include Workflow
  workflow do
    state :submitted do
      event :activate_via_link, :transitions_to => :proved_email
    end
    state :proved_email
  end

  def load_workflow_state
    self[:workflow_state]
  end

  def persist_workflow_state(new_value)
    self[:workflow_state] = new_value
    save!
  end
end


class CouchtinyExample < Test::Unit::TestCase

  def setup
    db = CouchTiny::Database.url("http://127.0.0.1:5984/test-workflow")
    db.delete_database! rescue nil
    db.create_database!
    User.use_database db
  end

  test 'CouchDB persistence' do
    user = User.new :email => 'manya@example.com'
    user.save!
    assert user.submitted?
    user.activate_via_link!
    assert user.proved_email?

    reloaded_user = User.get user.id
    puts reloaded_user.inspect
    assert reloaded_user.proved_email?, 'Reloaded user should have the desired workflow state'
  end
end

Version data entries

26 entries across 26 versions & 6 rubygems

Version Path
validating-workflow-0.7.12 test/couchtiny_example.rb
validating-workflow-0.7.11 test/couchtiny_example.rb
validating-workflow-0.7.10 test/couchtiny_example.rb
validating-workflow-0.7.9 test/couchtiny_example.rb
workflow-orchestrator-1.3.1 test/couchtiny_example.rb
workflow-orchestrator-1.3.0 test/couchtiny_example.rb
validating-workflow-0.7.7 test/couchtiny_example.rb
workflow-1.2.0 test/couchtiny_example.rb
validating-workflow-0.7.6 test/couchtiny_example.rb
workflow-1.1.0 test/couchtiny_example.rb
workflow-rails4-1.1.0 test/couchtiny_example.rb
workflow-1.0.0 test/couchtiny_example.rb
workflow-0.8.7 test/couchtiny_example.rb
workflow-0.8.6 test/couchtiny_example.rb
workflow-0.8.4 test/couchtiny_example.rb
workflow-0.8.3 test/couchtiny_example.rb
workflow-0.8.1 test/couchtiny_example.rb
railsware-workflow-0.8.1 test/couchtiny_example.rb
workflow-0.8.0 test/couchtiny_example.rb
validating-workflow-0.7.2 test/couchtiny_example.rb