mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 12:58:48 +01:00
Merge branch 'master' into new-gui
Conflicts: Gemfile.lock
This commit is contained in:
parent
fa537fbeb0
commit
eb1502d4e0
28 changed files with 385 additions and 221 deletions
|
|
@ -4,7 +4,6 @@ class PreferencesControllerTest < ActionController::TestCase
|
|||
|
||||
def setup
|
||||
super
|
||||
assert_equal "test", Rails.env
|
||||
assert_equal "change-me", Tracks::Config.salt
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||
login_as(:admin_user)
|
||||
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"hidden"}
|
||||
todos.each do |t|
|
||||
assert_equal :project_hidden, t.reload().aasm_current_state
|
||||
assert_equal :project_hidden, t.reload().aasm.current_state
|
||||
end
|
||||
assert p.reload().hidden?
|
||||
end
|
||||
|
|
@ -60,7 +60,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"hidden"}
|
||||
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"active"}
|
||||
todos.each do |t|
|
||||
assert_equal :active, t.reload().aasm_current_state
|
||||
assert_equal :active, t.reload().aasm.current_state
|
||||
end
|
||||
assert p.reload().active?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
xhr :post, :toggle_check, :id=>1, :_source_view=>""
|
||||
|
||||
recurring_todo_1 = RecurringTodo.find(1) # reload seems to not work
|
||||
assert recurring_todo_1.active?, "recurring todo should be active but is #{recurring_todo_1.aasm_current_state}"
|
||||
assert recurring_todo_1.active?, "recurring todo should be active but is #{recurring_todo_1.aasm.current_state}"
|
||||
|
||||
# by making active, a new todo should be created from the pattern
|
||||
assert_equal todo_count+1, Todo.count
|
||||
|
|
|
|||
2
test/fixtures/recurring_todos.yml
vendored
2
test/fixtures/recurring_todos.yml
vendored
|
|
@ -20,7 +20,7 @@ def two_weeks_hence
|
|||
end
|
||||
|
||||
def way_back
|
||||
Time.zone.local(2008,1,1)
|
||||
Time.zone.local(2008,1,1).to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ class PreferenceTest < ActiveSupport::TestCase
|
|||
fixtures :users, :preferences
|
||||
|
||||
def setup
|
||||
assert_equal "test", ENV['RAILS_ENV']
|
||||
assert_equal "change-me", Tracks::Config.salt
|
||||
@admin_user = User.find(1)
|
||||
@other_user = User.find(2)
|
||||
|
|
|
|||
|
|
@ -48,36 +48,36 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
# state machine
|
||||
|
||||
def test_project_initial_state_is_active
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
assert_equal :active, @timemachine.aasm.current_state
|
||||
assert @timemachine.active?
|
||||
end
|
||||
|
||||
def test_hide_project
|
||||
@timemachine.hide!
|
||||
assert_equal :hidden, @timemachine.aasm_current_state
|
||||
assert_equal :hidden, @timemachine.aasm.current_state
|
||||
assert @timemachine.hidden?
|
||||
end
|
||||
|
||||
def test_activate_project
|
||||
@timemachine.activate!
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
assert_equal :active, @timemachine.aasm.current_state
|
||||
assert @timemachine.active?
|
||||
end
|
||||
|
||||
def test_transition_to_another_state
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
assert_equal :active, @timemachine.aasm.current_state
|
||||
@timemachine.transition_to(:hidden)
|
||||
assert_equal :hidden, @timemachine.aasm_current_state
|
||||
assert_equal :hidden, @timemachine.aasm.current_state
|
||||
@timemachine.transition_to(:completed)
|
||||
assert_equal :completed, @timemachine.aasm_current_state
|
||||
assert_equal :completed, @timemachine.aasm.current_state
|
||||
@timemachine.transition_to(:active)
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
assert_equal :active, @timemachine.aasm.current_state
|
||||
end
|
||||
|
||||
def test_transition_to_same_state
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
assert_equal :active, @timemachine.aasm.current_state
|
||||
@timemachine.transition_to(:active)
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
assert_equal :active, @timemachine.aasm.current_state
|
||||
end
|
||||
|
||||
# other tests
|
||||
|
|
@ -95,7 +95,7 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
def test_complete_project
|
||||
assert_nil @timemachine.completed_at
|
||||
@timemachine.complete!
|
||||
assert_equal :completed, @timemachine.aasm_current_state
|
||||
assert_equal :completed, @timemachine.aasm.current_state
|
||||
assert @timemachine.completed?
|
||||
assert_not_nil @timemachine.completed_at, "completed_at not expected to be nil"
|
||||
assert_in_delta Time.now, @timemachine.completed_at, 1
|
||||
|
|
@ -150,7 +150,7 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
first_todo = @moremoney.todos[0]
|
||||
first_todo.show_from = Time.zone.now + 1.week
|
||||
first_todo.save!
|
||||
assert_equal :deferred, @moremoney.todos[0].aasm_current_state
|
||||
assert_equal :deferred, @moremoney.todos[0].aasm.current_state
|
||||
|
||||
assert_equal 1, @moremoney.todos.deferred.count
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
require 'date'
|
||||
require 'test/unit'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require_relative '../../app/services/rich_message_extractor.rb'
|
||||
|
|
@ -5,11 +6,15 @@ require_relative '../../app/services/rich_message_extractor.rb'
|
|||
class RichMessageExtractorTest < Test::Unit::TestCase
|
||||
|
||||
def test_message_with_all_options
|
||||
message = "ohai@some-context>in-this-project"
|
||||
message = "ohai@some-context~this-project>131012<131014#tag1#tag2*"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal "ohai", extractor.description
|
||||
assert_equal "some-context", extractor.context
|
||||
assert_equal "in-this-project", extractor.project
|
||||
assert_equal "this-project", extractor.project
|
||||
assert_equal "2013-10-12", extractor.show_from.to_s
|
||||
assert_equal "2013-10-14", extractor.due.to_s
|
||||
assert_equal ["tag1","tag2"], extractor.tags
|
||||
assert extractor.starred?
|
||||
end
|
||||
|
||||
def test_message_without_project
|
||||
|
|
@ -20,12 +25,12 @@ class RichMessageExtractorTest < Test::Unit::TestCase
|
|||
assert_equal nil, extractor.project
|
||||
end
|
||||
|
||||
def test_message_without_project
|
||||
message = " ohai @ some-context"
|
||||
def test_message_without_context
|
||||
message = " ohai ~ some-project"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal "ohai", extractor.description
|
||||
assert_equal "some-context", extractor.context
|
||||
assert_equal nil, extractor.project
|
||||
assert_equal "", extractor.context
|
||||
assert_equal "some-project", extractor.project
|
||||
end
|
||||
|
||||
def test_message_without_project_or_context
|
||||
|
|
@ -52,4 +57,52 @@ class RichMessageExtractorTest < Test::Unit::TestCase
|
|||
assert_equal nil, extractor.project
|
||||
end
|
||||
|
||||
def test_message_with_tags
|
||||
message = "some tags#tag 1#tag2"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal ["tag 1","tag2"], extractor.tags
|
||||
end
|
||||
|
||||
def test_message_with_no_tags
|
||||
message = "no tags"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal nil, extractor.tags
|
||||
end
|
||||
|
||||
def test_message_with_due_date
|
||||
message = "datetest<141013"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal "2014-10-13", extractor.due.to_s
|
||||
end
|
||||
|
||||
def test_message_with_no_due_date
|
||||
message = "no date"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal nil, extractor.due
|
||||
end
|
||||
|
||||
def test_message_with_show_from
|
||||
message = "datetest>161013"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal "2016-10-13", extractor.show_from.to_s
|
||||
end
|
||||
|
||||
def test_message_with_no_show_from
|
||||
message = "no tickler"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert_equal nil, extractor.show_from
|
||||
end
|
||||
|
||||
def test_message_with_star
|
||||
message = "star test*"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
assert extractor.starred?
|
||||
end
|
||||
|
||||
def test_message_with_no_star
|
||||
message = "no star test"
|
||||
extractor = RichMessageExtractor.new(message)
|
||||
refute extractor.starred?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,4 +18,23 @@ class TodoFromRichMessageTest < ActiveSupport::TestCase
|
|||
assert_equal default_context_id, new_todo.context_id
|
||||
end
|
||||
|
||||
def test_from_rich_message_adds_all_fields
|
||||
user = @completed.user
|
||||
context = Context.create(:name => 'context')
|
||||
project = Project.create(:name => 'project')
|
||||
message = "description@context~project>131014<131017#tag1#tag2*"
|
||||
builder = TodoFromRichMessage.new(user, context.id, message, "notes")
|
||||
new_todo = builder.construct
|
||||
|
||||
assert_not_nil new_todo
|
||||
assert_equal "description", new_todo.description
|
||||
assert_equal "notes", new_todo.notes
|
||||
assert_equal context.id, new_todo.context_id
|
||||
assert_equal project.id, new_todo.project_id
|
||||
assert_equal "2013-10-14 00:00:00 +0100", new_todo.show_from.to_s
|
||||
assert_equal "2013-10-17 00:00:00 +0100", new_todo.due.to_s
|
||||
assert_equal "starred, tag1, tag2", new_todo.tags.to_s
|
||||
assert new_todo.starred?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -97,10 +97,10 @@ class TodoTest < ActiveSupport::TestCase
|
|||
|
||||
def test_defer_an_existing_todo
|
||||
@not_completed2
|
||||
assert_equal :active, @not_completed2.aasm_current_state
|
||||
assert_equal :active, @not_completed2.aasm.current_state
|
||||
@not_completed2.show_from = Time.zone.now + 1.week
|
||||
assert @not_completed2.save, "should have saved successfully" + @not_completed2.errors.to_xml
|
||||
assert_equal :deferred, @not_completed2.aasm_current_state
|
||||
assert_equal :deferred, @not_completed2.aasm.current_state
|
||||
end
|
||||
|
||||
def test_create_a_new_deferred_todo
|
||||
|
|
@ -110,41 +110,41 @@ class TodoTest < ActiveSupport::TestCase
|
|||
todo.context_id = 1
|
||||
todo.description = 'foo'
|
||||
assert todo.save, "should have saved successfully" + todo.errors.to_xml
|
||||
assert_equal :deferred, todo.aasm_current_state
|
||||
assert_equal :deferred, todo.aasm.current_state
|
||||
end
|
||||
|
||||
def test_create_a_new_deferred_todo_by_passing_attributes
|
||||
user = users(:other_user)
|
||||
todo = user.todos.build(:show_from => next_week, :context_id => 1, :description => 'foo')
|
||||
assert todo.save, "should have saved successfully" + todo.errors.to_xml
|
||||
assert_equal :deferred, todo.aasm_current_state
|
||||
assert_equal :deferred, todo.aasm.current_state
|
||||
end
|
||||
|
||||
def test_toggle_completion
|
||||
t = @not_completed1
|
||||
assert_equal :active, t.aasm_current_state
|
||||
assert_equal :active, t.aasm.current_state
|
||||
t.toggle_completion!
|
||||
assert_equal :completed, t.aasm_current_state
|
||||
assert_equal :completed, t.aasm.current_state
|
||||
t.toggle_completion!
|
||||
assert_equal :active, t.aasm_current_state
|
||||
assert_equal :active, t.aasm.current_state
|
||||
end
|
||||
|
||||
def test_toggle_completion_with_show_from_in_future
|
||||
t = @not_completed1
|
||||
t.show_from= 1.week.from_now
|
||||
t.save!
|
||||
assert_equal :deferred, t.aasm_current_state
|
||||
assert_equal :deferred, t.aasm.current_state
|
||||
t.toggle_completion!
|
||||
assert_equal :completed, t.aasm_current_state
|
||||
assert_equal :completed, t.aasm.current_state
|
||||
end
|
||||
|
||||
def test_toggle_completion_with_show_from_in_past
|
||||
t = @not_completed1
|
||||
t.update_attribute(:show_from, 1.week.ago)
|
||||
assert_equal :active, t.aasm_current_state
|
||||
assert_equal :active, t.aasm.current_state
|
||||
|
||||
assert t.toggle_completion!, "shoud be able to mark active todo complete even if show_from is set in the past"
|
||||
assert_equal :completed, t.aasm_current_state
|
||||
assert_equal :completed, t.aasm.current_state
|
||||
end
|
||||
|
||||
def test_activate_also_saves
|
||||
|
|
@ -225,7 +225,7 @@ class TodoTest < ActiveSupport::TestCase
|
|||
t.context_id = 1
|
||||
t.save!
|
||||
t.reload
|
||||
assert_equal :active, t.aasm_current_state
|
||||
assert_equal :active, t.aasm.current_state
|
||||
end
|
||||
|
||||
def test_initial_state_is_deferred_when_show_from_in_future
|
||||
|
|
@ -236,7 +236,7 @@ class TodoTest < ActiveSupport::TestCase
|
|||
t.show_from = 1.week.from_now.to_date
|
||||
t.save!
|
||||
t.reload
|
||||
assert_equal :deferred, t.aasm_current_state
|
||||
assert_equal :deferred, t.aasm.current_state
|
||||
end
|
||||
|
||||
def test_todo_is_not_starred
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'timecop'
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :recurring_todos
|
||||
|
||||
def setup
|
||||
assert_equal "test", ENV['RAILS_ENV']
|
||||
assert_equal "change-me", Tracks::Config.salt
|
||||
@admin_user = User.find(1)
|
||||
@other_user = User.find(2)
|
||||
|
|
@ -374,16 +374,16 @@ class UserTest < ActiveSupport::TestCase
|
|||
|
||||
# test group counts for projects and contexts
|
||||
project_counts = u.todos.count_by_group(:project_id)
|
||||
assert_equal "6,3,4,4", project_counts.map{|pc|pc[1]}.join(",")
|
||||
assert_equal [6,3,4,4], project_counts.values
|
||||
|
||||
context_counts = u.todos.count_by_group(:context_id)
|
||||
assert_equal "7,3,1,3,1,2", context_counts.map{|cc|cc[1]}.join(",")
|
||||
assert_equal [7,3,1,3,1,2], context_counts.values
|
||||
|
||||
# add a todo to the first context and check that the count is increased
|
||||
u.todos.create!(:description => "yet another todo", :context => u.contexts.first)
|
||||
|
||||
context_counts = u.todos.reload.count_by_group(:context_id)
|
||||
assert_equal "8,3,1,3,1,2", context_counts.map{|cc|cc[1]}.join(",")
|
||||
assert_equal [8,3,1,3,1,2], context_counts.values
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
@ -393,4 +393,4 @@ class UserTest < ActiveSupport::TestCase
|
|||
User.create({ :login => 'quire', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue