mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-02 14:11:46 +01:00
add state machine to context including a closed state
This commit is contained in:
parent
3c6b1737c1
commit
99eed9f638
4 changed files with 93 additions and 28 deletions
28
test/fixtures/contexts.yml
vendored
28
test/fixtures/contexts.yml
vendored
|
|
@ -10,7 +10,7 @@ agenda:
|
|||
id: 1
|
||||
name: agenda
|
||||
position: 1
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -19,7 +19,7 @@ call:
|
|||
id: 2
|
||||
name: call
|
||||
position: 2
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -28,7 +28,7 @@ email:
|
|||
id: 3
|
||||
name: email
|
||||
position: 3
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -37,7 +37,7 @@ errand:
|
|||
id: 4
|
||||
name: errand
|
||||
position: 4
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -46,7 +46,7 @@ lab:
|
|||
id: 5
|
||||
name: lab
|
||||
position: 5
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -55,7 +55,7 @@ library:
|
|||
id: 6
|
||||
name: library
|
||||
position: 6
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -64,7 +64,7 @@ freetime:
|
|||
id: 7
|
||||
name: freetime
|
||||
position: 7
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -73,7 +73,7 @@ office:
|
|||
id: 8
|
||||
name: office
|
||||
position: 8
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -82,7 +82,7 @@ waitingfor:
|
|||
id: 9
|
||||
name: waiting for
|
||||
position: 9
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -91,7 +91,7 @@ office_otheruser:
|
|||
id: 10
|
||||
name: office
|
||||
position: 1
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 2
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -100,7 +100,7 @@ waitingfor_otheruser:
|
|||
id: 11
|
||||
name: waiting for
|
||||
position: 2
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 2
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -109,7 +109,7 @@ someday_maybe:
|
|||
id: 12
|
||||
name: someday maybe
|
||||
position: 10
|
||||
hide: true
|
||||
state: hidden
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -118,7 +118,7 @@ inbox:
|
|||
id: 13
|
||||
name: Inbox
|
||||
position: 1
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 4
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
@ -127,7 +127,7 @@ anothercontext:
|
|||
id: 14
|
||||
name: anothercontext
|
||||
position: 2
|
||||
hide: false
|
||||
state: active
|
||||
user_id: 4
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
|
|||
|
|
@ -54,14 +54,6 @@ class ContextTest < ActiveSupport::TestCase
|
|||
assert_equal @agenda.name, @agenda.title
|
||||
end
|
||||
|
||||
def test_hidden_attr_reader
|
||||
assert !@agenda.hidden?
|
||||
@agenda.hide = true
|
||||
@agenda.save!
|
||||
@agenda.reload
|
||||
assert_equal true, @agenda.hidden?
|
||||
end
|
||||
|
||||
def test_null_object
|
||||
c = Context.null_object
|
||||
assert c.nil?
|
||||
|
|
@ -75,4 +67,34 @@ class ContextTest < ActiveSupport::TestCase
|
|||
assert c.new_record_before_save?, "newly created record should be new_record"
|
||||
end
|
||||
|
||||
def test_hide_context
|
||||
assert @agenda.active?
|
||||
@agenda.hide!
|
||||
assert @agenda.hidden?
|
||||
end
|
||||
|
||||
def test_closing_context_guarded_for_active_todos
|
||||
assert @agenda.active?
|
||||
assert AASM::InvalidTransition do
|
||||
@agenda.close!
|
||||
end
|
||||
|
||||
@agenda.todos.active.each {|t| t.complete! }
|
||||
@agenda.close!
|
||||
assert @agenda.closed?
|
||||
end
|
||||
|
||||
def test_activating_closed_context
|
||||
# given a context @agenda that is closed
|
||||
@agenda.todos.active.each {|t| t.complete! }
|
||||
@agenda.close!
|
||||
assert @agenda.closed?
|
||||
|
||||
# when I activate @agenda
|
||||
@agenda.activate!
|
||||
|
||||
# then @agenda should have an active state
|
||||
assert @agenda.active?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue