mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 07:48:50 +01:00
all non-cucumber tests are passing
This commit is contained in:
parent
13b58f3a10
commit
63175c115b
46 changed files with 248 additions and 505 deletions
100
backup.rails2.3/spec/models/context_spec.rb
Normal file
100
backup.rails2.3/spec/models/context_spec.rb
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe Context do
|
||||
def valid_attributes
|
||||
{:name => 'Errands'}
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@context = Context.new
|
||||
end
|
||||
|
||||
it 'has many users' do
|
||||
Context.should have_many(:todos).
|
||||
with_order('todos.due IS NULL, todos.due ASC, todos.created_at ASC').
|
||||
with_dependent(:delete_all).
|
||||
with_include(:project)
|
||||
end
|
||||
|
||||
it_should_belong_to :user
|
||||
|
||||
it_should_validate_presence_of :name, 'context must have a name'
|
||||
it_should_validate_length_of :name, :maximum => 255,
|
||||
:message_too_long => 'context name must be less than 256 characters'
|
||||
it_should_validate_uniqueness_of :name, 'already exists' # TODO: scope user_id
|
||||
it_should_not_accept_as_valid :name, ',',
|
||||
:message => "cannot contain the comma (',') character"
|
||||
|
||||
it 'is hidden when hide is true' do
|
||||
Context.new(:hide => false).should_not be_hidden
|
||||
Context.new(:hide => true).should be_hidden
|
||||
end
|
||||
|
||||
it 'returns name as title' do
|
||||
Context.new(:name => 'foo').title.should == 'foo'
|
||||
end
|
||||
|
||||
it 'returns an instance NullContext for null_object' do
|
||||
Context.null_object.should be_an_instance_of(NullContext)
|
||||
end
|
||||
|
||||
it "returns feed options with description containing user's name" do
|
||||
user = mock_model(User, :display_name => 'simon')
|
||||
feed_options_for_user = Context.feed_options(user)
|
||||
feed_options_for_user[:title].should == 'Tracks Contexts'
|
||||
feed_options_for_user[:description].should == 'Lists all the contexts for simon'
|
||||
end
|
||||
|
||||
describe 'when finding by namepart' do
|
||||
fixtures :todos, :contexts
|
||||
|
||||
it 'finds with exact match' do
|
||||
Context.find_by_namepart('agenda').should == contexts(:agenda)
|
||||
end
|
||||
|
||||
it 'finds with partial match' do
|
||||
Context.find_by_namepart('age').should == contexts(:agenda)
|
||||
end
|
||||
|
||||
it 'deletes todos within context when context deleted' do
|
||||
contexts(:agenda).should have(3).todos
|
||||
call_todos = contexts(:agenda).todos
|
||||
contexts(:agenda).destroy
|
||||
Todo.find(:all).should_not include(call_todos)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when counting todos' do
|
||||
fixtures :todos, :contexts, :users, :preferences
|
||||
|
||||
it 'returns correct number of completed todos' do
|
||||
contexts(:call).done_todos.should_not have(:any).items
|
||||
contexts(:call).todos.first.complete!
|
||||
Context.find(contexts(:call).id).done_todos.should have(1).items
|
||||
end
|
||||
|
||||
it 'returns correct number of not done todos' do
|
||||
contexts(:agenda).todos.not_completed.should have(2).items
|
||||
contexts(:agenda).todos.last.complete!
|
||||
contexts(:agenda).todos.not_completed.should have(1).items
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe NullContext do
|
||||
before(:each) do
|
||||
@context = NullContext.new
|
||||
end
|
||||
|
||||
it 'is nil' do
|
||||
@context.should be_nil
|
||||
end
|
||||
|
||||
it 'has no id' do
|
||||
@context.id.should be_nil
|
||||
end
|
||||
|
||||
it 'has a blank name' do
|
||||
@context.name.should be_blank
|
||||
end
|
||||
end
|
||||
29
backup.rails2.3/spec/models/message_gateway_spec.rb
Normal file
29
backup.rails2.3/spec/models/message_gateway_spec.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe MessageGateway do
|
||||
before :each do
|
||||
todo = mock_model(Todo, :description= => nil, :raw_notes= => nil, :context_id= => nil, :save! => nil)
|
||||
|
||||
@user = mock_model(User,
|
||||
:prefs => mock_model(Preference, :sms_context => mock_model(Context)),
|
||||
:todos => mock('Todo collection', :find => nil, :build => todo),
|
||||
:contexts => mock('Context collection', :exists? => true, :find => nil))
|
||||
|
||||
User.stub!(:find).and_return(@user)
|
||||
end
|
||||
|
||||
def load_message(filename)
|
||||
MessageGateway.receive(File.read(File.join(RAILS_ROOT, 'test', 'fixtures', filename)))
|
||||
end
|
||||
|
||||
|
||||
it "should dispatch on From: or To: according to site.yml" do
|
||||
SITE_CONFIG['email_dispatch'] = 'from'
|
||||
User.should_receive(:find).with(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", '5555555555@tmomail.net'])
|
||||
load_message('sample_email.txt')
|
||||
|
||||
SITE_CONFIG['email_dispatch'] = 'to'
|
||||
User.should_receive(:find).with(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", 'gtd@tracks.com'])
|
||||
load_message('sample_email.txt')
|
||||
end
|
||||
end
|
||||
182
backup.rails2.3/spec/models/todo_spec.rb
Normal file
182
backup.rails2.3/spec/models/todo_spec.rb
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe Todo do
|
||||
def valid_attributes(attributes={})
|
||||
{
|
||||
:description => "don't forget the milk",
|
||||
:context => mock_model(Context, :name => 'errands', :destroyed? => false)
|
||||
}.merge(attributes)
|
||||
end
|
||||
|
||||
def create_todo(attributes={})
|
||||
todo = Todo.new(valid_attributes(attributes))
|
||||
todo.stub!(:user).and_return(mock_model(User, :date => Time.zone.now))
|
||||
todo.save!
|
||||
todo
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@todo = Todo.new
|
||||
end
|
||||
|
||||
it_should_belong_to :context
|
||||
it_should_belong_to :project
|
||||
it_should_belong_to :user
|
||||
|
||||
it_should_validate_presence_of :description
|
||||
it_should_validate_presence_of :context
|
||||
it_should_validate_length_of :description, :maximum => 100
|
||||
it_should_validate_length_of :notes, :maximum => 60_000
|
||||
|
||||
it 'validates presence of show_from when deferred'
|
||||
|
||||
it 'ensures that show_from is a date in the future' do
|
||||
todo = Todo.new(valid_attributes)
|
||||
todo.stub!(:user).and_return(mock_model(User, :date => Time.zone.now))
|
||||
todo.show_from = 3.days.ago
|
||||
todo.should have(1).error_on(:show_from)
|
||||
end
|
||||
|
||||
it 'allows show_from to be blank' do
|
||||
todo = Todo.new(valid_attributes(:show_from => ''))
|
||||
todo.should_not have(:any).error_on(:show_from)
|
||||
end
|
||||
|
||||
describe 'states' do
|
||||
it 'is active on initializing' do
|
||||
create_todo.should be_active
|
||||
end
|
||||
|
||||
it 'is deferred when show from is in the future' do
|
||||
todo = create_todo
|
||||
todo.show_from = 1.week.from_now
|
||||
todo.should be_deferred
|
||||
end
|
||||
|
||||
describe 'active' do
|
||||
%w(project_hidden completed deferred).each do |from_state|
|
||||
it "is activable from `#{from_state}'" do
|
||||
todo = create_todo
|
||||
todo.state = from_state
|
||||
todo.send("#{from_state}?").should be_true
|
||||
todo.activate!
|
||||
todo.should be_active
|
||||
end
|
||||
end
|
||||
|
||||
it 'clears show_from when entering active state' do
|
||||
todo = create_todo
|
||||
todo.show_from = 3.days.from_now
|
||||
todo.should be_deferred
|
||||
todo.activate!
|
||||
todo.should be_active
|
||||
todo.show_from.should be_nil
|
||||
end
|
||||
|
||||
it 'clears completed_at when entering active state' do
|
||||
todo = create_todo
|
||||
todo.complete!
|
||||
todo.should be_completed
|
||||
todo.activate!
|
||||
todo.should be_active
|
||||
todo.completed_at.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'completed' do
|
||||
%w(active project_hidden deferred).each do |from_state|
|
||||
it "is completable from `#{from_state}'" do
|
||||
todo = create_todo
|
||||
todo.state = from_state
|
||||
todo.send("#{from_state}?").should be_true
|
||||
todo.complete!
|
||||
todo.should be_completed
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets complated_at' do
|
||||
todo = create_todo
|
||||
todo.complete!
|
||||
todo.completed_at.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'project_hidden' do
|
||||
%w(active deferred).each do |from_state|
|
||||
it "is hiddable from `#{from_state}'" do
|
||||
todo = create_todo
|
||||
todo.state = from_state
|
||||
todo.send("#{from_state}?").should be_true
|
||||
todo.hide!
|
||||
todo.should be_project_hidden
|
||||
end
|
||||
end
|
||||
|
||||
it 'unhides to active when not show_from' do
|
||||
todo = create_todo(:show_from => '')
|
||||
todo.hide!
|
||||
todo.should be_project_hidden
|
||||
todo.unhide!
|
||||
todo.should be_active
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when toggling completion' do
|
||||
it 'toggles to active when completed' do
|
||||
todo = create_todo
|
||||
todo.complete!
|
||||
todo.should be_completed
|
||||
todo.toggle_completion!
|
||||
todo.should be_active
|
||||
end
|
||||
|
||||
it 'toggles to completed when not completed' do
|
||||
todo = create_todo
|
||||
todo.should_not be_completed
|
||||
todo.toggle_completion!
|
||||
todo.should be_completed
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when retrieving project' do
|
||||
it 'returns project if set' do
|
||||
project = mock_model(Project)
|
||||
todo = Todo.new(:project => project)
|
||||
todo.project.should == project
|
||||
end
|
||||
|
||||
it 'returns a NullProject if not set' do
|
||||
Todo.new.project.should be_an_instance_of(NullProject)
|
||||
end
|
||||
end
|
||||
|
||||
describe('when setting show_from') { it 'is speced' }
|
||||
|
||||
it 'is starred if tag is "starred"' do
|
||||
todo = create_todo
|
||||
todo.should_not be_starred
|
||||
todo._add_tags('starred')
|
||||
todo.reload
|
||||
todo.should be_starred
|
||||
end
|
||||
|
||||
describe 'when toggling star flag' do
|
||||
it 'toggles to not starred when starred' do
|
||||
todo = create_todo
|
||||
todo._add_tags('starred')
|
||||
todo.should be_starred
|
||||
todo.toggle_star!
|
||||
todo.reload
|
||||
todo.should_not be_starred
|
||||
end
|
||||
|
||||
it 'toggles to starred when not starred' do
|
||||
todo = create_todo
|
||||
todo.should_not be_starred
|
||||
todo.toggle_star!
|
||||
todo.reload
|
||||
todo.should be_starred
|
||||
end
|
||||
end
|
||||
end
|
||||
168
backup.rails2.3/spec/models/user_spec.rb
Normal file
168
backup.rails2.3/spec/models/user_spec.rb
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe User do
|
||||
def valid_attributes(attributes={})
|
||||
{
|
||||
:login => 'simon',
|
||||
:password => 'foobarspam',
|
||||
:password_confirmation => 'foobarspam'
|
||||
}.merge(attributes)
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
describe 'associations' do
|
||||
it 'has many contexts' do
|
||||
User.should have_many(:contexts).
|
||||
with_order('position ASC').
|
||||
with_dependent(:delete_all)
|
||||
end
|
||||
|
||||
it 'has many projects' do
|
||||
User.should have_many(:projects).
|
||||
with_order('projects.position ASC').
|
||||
with_dependent(:delete_all)
|
||||
end
|
||||
|
||||
it 'has many todos' do
|
||||
User.should have_many(:todos).
|
||||
with_order('todos.completed_at DESC, todos.created_at DESC').
|
||||
with_dependent(:delete_all)
|
||||
end
|
||||
|
||||
it 'has many deferred todos' do
|
||||
User.should have_many(:deferred_todos).
|
||||
with_order('show_from ASC, todos.created_at DESC').
|
||||
with_conditions('state = ?', 'deferred').
|
||||
with_class_name('Todo')
|
||||
end
|
||||
|
||||
it 'has many notes' do
|
||||
User.should have_many(:notes).
|
||||
with_order('created_at DESC').
|
||||
with_dependent(:delete_all)
|
||||
end
|
||||
|
||||
it 'has one preference' do
|
||||
User.should have_one(:preference)
|
||||
end
|
||||
end
|
||||
|
||||
it_should_validate_presence_of :login
|
||||
it_should_validate_presence_of :password
|
||||
it_should_validate_presence_of :password_confirmation
|
||||
|
||||
it_should_validate_length_of :password, :within => 5..40
|
||||
it_should_validate_length_of :login, :within => 3..80
|
||||
|
||||
it_should_validate_uniqueness_of :login
|
||||
it_should_validate_confirmation_of :password
|
||||
|
||||
it 'validates presence of password only when password is required'
|
||||
it 'validates presence of password_confirmation only when password is required'
|
||||
it 'validates confirmation of password only when password is required'
|
||||
it 'validates presence of open_id_url only when using openid'
|
||||
|
||||
it 'accepts only allow auth_type authorized by the admin' do
|
||||
Tracks::Config.should_receive(:auth_schemes).exactly(3).times.and_return(%w(database open_id))
|
||||
User.new(valid_attributes(:auth_type => 'database')).should_not have(:any).error_on(:auth_type)
|
||||
User.new(valid_attributes(:auth_type => 'open_id')).should_not have(:any).error_on(:auth_type)
|
||||
User.new(valid_attributes(:auth_type => 'ldap')).should have(1).error_on(:auth_type)
|
||||
end
|
||||
|
||||
it 'returns login for #to_param' do
|
||||
@user.login = 'john'
|
||||
@user.to_param.should == 'john'
|
||||
end
|
||||
|
||||
it 'has a custom finder to find admin' do
|
||||
User.should_receive(:find).with(:first, :conditions => ['is_admin = ?', true])
|
||||
User.find_admin
|
||||
end
|
||||
|
||||
it 'has a custom finder to find by openid url'
|
||||
it 'knows if there is any user through #no_users_yet? (TODO: better description)'
|
||||
|
||||
describe 'when choosing what do display as a name' do
|
||||
it 'displays login when no first name and last name' do
|
||||
User.new(valid_attributes).display_name.should == 'simon'
|
||||
end
|
||||
|
||||
it 'displays last name when no first name' do
|
||||
User.new(valid_attributes(:last_name => 'foo')).display_name.should == 'foo'
|
||||
end
|
||||
|
||||
it 'displays first name when no last name' do
|
||||
User.new(valid_attributes(:first_name => 'bar')).display_name.should == 'bar'
|
||||
end
|
||||
|
||||
it 'displays first name and last name when both specified' do
|
||||
User.new(valid_attributes(:first_name => 'foo', :last_name => 'bar')).display_name.should == 'foo bar'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'authentication' do
|
||||
before(:each) do
|
||||
@user = User.create!(valid_attributes)
|
||||
end
|
||||
|
||||
it 'authenticates user' do
|
||||
User.authenticate('simon', 'foobarspam').id.should be @user.id
|
||||
end
|
||||
|
||||
it 'resets password' do
|
||||
@user.update_attributes(
|
||||
:password => 'new password',
|
||||
:password_confirmation => 'new password'
|
||||
)
|
||||
User.authenticate('simon', 'foobarspam').should be_nil
|
||||
User.authenticate('simon', 'new password').id.should be @user.id
|
||||
end
|
||||
|
||||
it 'does not rehash password after update of login' do
|
||||
@user.update_attribute(:login, 'foobar')
|
||||
User.authenticate('foobar', 'foobarspam').id.should be @user.id
|
||||
end
|
||||
|
||||
it 'sets remember token' do
|
||||
@user.remember_me
|
||||
@user.remember_token.should_not be_nil
|
||||
@user.remember_token_expires_at.should_not be_nil
|
||||
end
|
||||
|
||||
it 'unsets remember token' do
|
||||
@user.remember_me
|
||||
@user.remember_token.should_not be_nil
|
||||
@user.forget_me
|
||||
@user.remember_token.should be_nil
|
||||
end
|
||||
|
||||
it 'remembers me default two weeks' do
|
||||
before = 2.weeks.from_now.utc
|
||||
@user.remember_me
|
||||
after = 2.weeks.from_now.utc
|
||||
@user.remember_token.should_not be_nil
|
||||
@user.remember_token_expires_at.should_not be_nil
|
||||
@user.remember_token_expires_at.should be_between(before, after)
|
||||
end
|
||||
end
|
||||
|
||||
it "should not activate todos that are showing when UTC is tomorrow" do
|
||||
context = Context.create(:name => 'a context')
|
||||
user = User.create(:login => 'user7', :password => 'foobar', :password_confirmation => 'foobar')
|
||||
user.save!
|
||||
user.create_preference
|
||||
user.preference.update_attribute('time_zone', 'Pacific Time (US & Canada)')
|
||||
# Time.zone = 'Pacific Time (US & Canada)'
|
||||
Time.stub!(:now).and_return(Time.new.end_of_day - 20.minutes)
|
||||
todo = user.todos.build(:description => 'test task', :context => context)
|
||||
todo.show_from = user.date + 1.days
|
||||
todo.save!
|
||||
|
||||
user.deferred_todos.find_and_activate_ready
|
||||
user = User.find(user.id)
|
||||
user.deferred_todos.should include(todo)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue