-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathcouchtiny_example.rb
46 lines (38 loc) · 1.03 KB
/
couchtiny_example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 < Minitest::Test
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.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