solve merge conflict

Merge branch 'master' of git://github.com/bsag/tracks

Conflicts:

	.gitignore
This commit is contained in:
Reinier Balt 2008-06-24 20:36:40 +02:00
commit 258958ebdf
4 changed files with 108 additions and 276 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ db/data.yml
db/*.sqlite3
nbproject
vendor/plugins/query_trace/
db/schema.rb

View file

@ -1,151 +0,0 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 38) do
create_table "contexts", :force => true do |t|
t.string "name", :null => false
t.integer "position"
t.boolean "hide", :default => false
t.integer "user_id", :default => 1
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "contexts", ["user_id", "name"], :name => "index_contexts_on_user_id_and_name"
add_index "contexts", ["user_id"], :name => "index_contexts_on_user_id"
create_table "notes", :force => true do |t|
t.integer "user_id", :null => false
t.integer "project_id", :null => false
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "notes", ["user_id"], :name => "index_notes_on_user_id"
add_index "notes", ["project_id"], :name => "index_notes_on_project_id"
create_table "open_id_associations", :force => true do |t|
t.binary "server_url"
t.string "handle"
t.binary "secret"
t.integer "issued"
t.integer "lifetime"
t.string "assoc_type"
end
create_table "open_id_nonces", :force => true do |t|
t.string "nonce"
t.integer "created"
end
create_table "open_id_settings", :force => true do |t|
t.string "setting"
t.binary "value"
end
create_table "preferences", :force => true do |t|
t.integer "user_id", :null => false
t.string "date_format", :limit => 40, :default => "%d/%m/%Y", :null => false
t.integer "week_starts", :default => 0, :null => false
t.integer "show_number_completed", :default => 5, :null => false
t.integer "staleness_starts", :default => 7, :null => false
t.boolean "show_completed_projects_in_sidebar", :default => true, :null => false
t.boolean "show_hidden_contexts_in_sidebar", :default => true, :null => false
t.integer "due_style", :default => 0, :null => false
t.string "admin_email", :default => "butshesagirl@rousette.org.uk", :null => false
t.integer "refresh", :default => 0, :null => false
t.boolean "verbose_action_descriptors", :default => false, :null => false
t.boolean "show_hidden_projects_in_sidebar", :default => true, :null => false
t.string "time_zone", :default => "London", :null => false
t.boolean "show_project_on_todo_done", :default => false, :null => false
t.string "title_date_format", :default => "%A, %d %B %Y", :null => false
t.integer "mobile_todos_per_page", :default => 6, :null => false
end
add_index "preferences", ["user_id"], :name => "index_preferences_on_user_id"
create_table "projects", :force => true do |t|
t.string "name", :null => false
t.integer "position"
t.integer "user_id", :default => 1
t.text "description"
t.string "state", :limit => 20, :default => "active", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "default_context_id"
t.datetime "completed_at"
end
add_index "projects", ["user_id", "name"], :name => "index_projects_on_user_id_and_name"
add_index "projects", ["user_id"], :name => "index_projects_on_user_id"
create_table "sessions", :force => true do |t|
t.string "session_id"
t.text "data"
t.datetime "updated_at"
end
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
create_table "taggings", :force => true do |t|
t.integer "taggable_id"
t.integer "tag_id"
t.string "taggable_type"
t.integer "user_id"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type"], :name => "index_taggings_on_tag_id_and_taggable_id_and_taggable_type"
create_table "tags", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "tags", ["name"], :name => "index_tags_on_name"
create_table "todos", :force => true do |t|
t.integer "context_id", :null => false
t.integer "project_id"
t.string "description", :null => false
t.text "notes"
t.datetime "created_at"
t.date "due"
t.datetime "completed_at"
t.integer "user_id", :default => 1
t.date "show_from"
t.string "state", :limit => 20, :default => "immediate", :null => false
end
add_index "todos", ["user_id", "context_id"], :name => "index_todos_on_user_id_and_context_id"
add_index "todos", ["context_id"], :name => "index_todos_on_context_id"
add_index "todos", ["project_id"], :name => "index_todos_on_project_id"
add_index "todos", ["user_id", "project_id"], :name => "index_todos_on_user_id_and_project_id"
add_index "todos", ["user_id", "state"], :name => "index_todos_on_user_id_and_state"
create_table "users", :force => true do |t|
t.string "login", :limit => 80, :null => false
t.string "crypted_password", :limit => 40, :null => false
t.string "token"
t.boolean "is_admin", :default => false, :null => false
t.string "first_name"
t.string "last_name"
t.string "auth_type", :default => "database", :null => false
t.string "open_id_url"
t.string "remember_token"
t.datetime "remember_token_expires_at"
end
add_index "users", ["login"], :name => "index_users_on_login"
end

View file

@ -1,151 +1,105 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
module ContextSpecHelper
def valid_context_attributes
{
:name => "FooBar",
:position => 1,
:hide => true,
:user_id => 1
}
describe Context do
def valid_attributes
{:name => 'Errands'}
end
end
describe "Context validations" do
include ContextSpecHelper
before(:each) do
@context = Context.new
end
it "should be valid" do
@context.attributes = valid_context_attributes
@context.should be_valid
@context.save
Context.should have(4).records # 3 in fixtures 1 set up here
it 'has many users' do
Context.should have_many(:todos).
with_order('todos.completed_at DESC').
with_dependent(:delete_all).
with_include(:project)
end
it "should have two errors with a missing name" do
@context.attributes = valid_context_attributes.except(:name)
@context.should_not be_valid
@context.should have(2).error_on(:name)
@context.errors.on(:name)[0].should eql("context must have a name")
@context.errors.on(:name)[1].should eql("context name must be less than 256 characters")
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 "should have one error with a name of more than 255 characters" do
@context.name = "z" * 256
@context.should_not be_valid
@context.should have(1).error_on(:name)
@context.errors.on(:name).should eql("context name must be less than 256 characters")
it 'produces correct summary depending on visibility' do
Context.new(:hide => true).summary(3).should == '<p>3. Context is Hidden.</p>'
Context.new(:hide => false).summary(3).should == '<p>3. Context is Active.</p>'
end
it "should have one error with name containing comma" do
@context.name = "Foo,Bar"
@context.should_not be_valid
@context.should have(1).error_on(:name)
@context.errors.on(:name).should eql("cannot contain the comma (',') character")
it 'returns name as title' do
Context.new(:name => 'foo').title.should == 'foo'
end
it "should have one error if name already exists for user" do
@existing_context = Context.new
@existing_context.attributes = valid_context_attributes
@existing_context.save
@context.attributes = valid_context_attributes
@context.should_not be_valid
@context.should have(1).error_on(:name)
@context.errors.on(:name).should eql("already exists")
it 'returns an instance NullContext for null_object' do
Context.null_object.should be_an_instance_of(NullContext)
end
it "should have one record in Context model class" do
@context.name = "FooBar"
@context.save
Context.should have(4).records # 3 in fixture, one set up here
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
scenario :todos
it 'finds with exact match' do
Context.find_by_namepart('errand').should == contexts(:errand)
end
it 'finds with partial match' do
Context.find_by_namepart('err').should == contexts(:errand)
end
it 'deletes todos within context when context deleted' do
contexts(:call).should have(2).todos
call_todos = contexts(:call).todos
contexts(:call).destroy
Todo.find(:all).should_not include(call_todos)
end
end
describe 'when counting todos' do
scenario :todos
it 'returns correct number of completed todos' do
contexts(:call).should_not have(:any).done_todos
contexts(:call).todos.first.complete!
contexts(:call).should have(1).done_todos
end
it 'returns correct number of not done todos' do
contexts(:call).should have(2).not_done_todos
contexts(:call).todos.last.complete!
contexts(:call).should have(1).not_done_todos
end
end
end
describe "Context model" do
fixtures :users, :todos, :contexts, :preferences
include ContextSpecHelper
it "should show hidden" do
contexts(:call).should be_hide # :hide should be true
describe NullContext do
before(:each) do
@context = NullContext.new
end
it "should be produce correct .summary text for hidden context" do
contexts(:call).summary(1).should eql("<p>1. Context is Hidden.</p>")
it 'is nil' do
@context.should be_nil
end
it "should show not hidden" do
contexts(:call).hide = false
contexts(:call).should_not be_hide # :hide should be true
it 'has no id' do
@context.id.should be_nil
end
it "should produce correct .summary text for active context" do
contexts(:call).hide = false
contexts(:call).summary(1).should eql("<p>1. Context is Active.</p>")
it 'has a blank name' do
@context.name.should be_blank
end
it "should return .title which matches name" do
contexts(:agenda).title.should eql(contexts(:agenda).name)
end
it "should .find_by_namepart with exact match" do
@found = Context.find_by_namepart('agenda')
@found.should_not eql(nil)
@found.id.should eql(contexts(:agenda).id)
end
it "should .find_by_namepart with partial match" do
@found = Context.find_by_namepart('ag')
@found.should_not eql(nil)
@found.id.should eql(contexts(:agenda).id)
end
it "should return id with .to_param" do
Context.find(2).to_param.should eql("2")
end
it "should return feed options" do
opts = Context.feed_options(users(:admin_user))
opts[:title].should eql("Tracks Contexts")
opts[:description].should eql("Lists all the contexts for Admin Schmadmin")
end
it "should create null Context with .null_object" do
@empty = Context.null_object
@empty.should be_an_instance_of(NullContext)
@empty.id.should eql(nil)
@empty.name.should eql('')
end
it "should delete todos within context when context deleted" do
contexts(:agenda).todos.count.should eql(3)
agenda_todo_ids = contexts(:agenda).todos.collect{|t| t.id }
contexts(:agenda).destroy
agenda_todo_ids.each do |todo_id|
Todo.find(:all).should_not include(todo_id)
end
end
it "should return correct number of done todos" do
contexts(:agenda).done_todos.size.should eql(1)
t = contexts(:agenda).not_done_todos[0]
t.complete!
t.save!
Context.find(contexts(:agenda)).done_todos.size.should eql(2)
end
it "should return correct number of not done todos" do
contexts(:agenda).not_done_todos.size.should eql(2)
t = contexts(:agenda).not_done_todos[0]
t.complete!
t.save!
Context.find(contexts(:agenda)).not_done_todos.size.should eql(1)
end
end

View file

@ -4,6 +4,34 @@ ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec'
require 'spec/rails'
require 'skinny_spec'
require 'scenarios'
module LuckySneaks
module ModelSpecHelpers
module ExampleGroupLevelMethods
def it_should_validate_length_of(attribute, options={})
maximum = options[:maximum] || (options[:within] || []).last || false
minimum = options[:minimum] || (options[:within] || []).first || false
raise ArgumentError unless maximum || minimum
it "should not be valid if #{attribute} length is more than #{maximum}" do
instance.send "#{attribute}=", 'x'*(maximum+1)
instance.errors_on(attribute).should include(
options[:message_too_long] || ActiveRecord::Errors.default_error_messages[:too_long] % maximum
)
end if maximum
it "should not be valid if #{attribute} length is less than #{minimum}" do
instance.send "#{attribute}=", 'x'*(minimum-1)
instance.errors_on(attribute).should include(
options[:message_to_short] || ActiveRecord::Errors.default_error_messages[:too_short] % minimum
)
end if minimum
end
end
end
end
Spec::Runner.configure do |config|
# If you're not using ActiveRecord you should remove these