Eliminated use of scenarios plugin

It doesn't work on Rails 2.3.5
This commit is contained in:
Eric Allen 2009-12-08 13:13:21 -05:00
parent d1fc119e2d
commit 6d3770c5fb
42 changed files with 24 additions and 1576 deletions

View file

@ -55,3 +55,14 @@ buymilk:
due: ~
completed_at: <%= today %>
user: admin_user
callmom:
id: 5
context_id: 3 # call
project_id: ~
description: Call mom
notes: Remember her birthday
state: active
due: ~
completed_at: ~
user: admin_user

View file

@ -51,37 +51,37 @@ describe Context do
end
describe 'when finding by namepart' do
scenario :todos
fixtures :todos, :contexts
it 'finds with exact match' do
Context.find_by_namepart('errand').should == contexts(:errand)
Context.find_by_namepart('agenda').should == contexts(:agenda)
end
it 'finds with partial match' do
Context.find_by_namepart('err').should == contexts(:errand)
Context.find_by_namepart('age').should == contexts(:agenda)
end
it 'deletes todos within context when context deleted' do
contexts(:call).should have(2).todos
call_todos = contexts(:call).todos
contexts(:call).destroy
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
scenario :todos
fixtures :todos, :contexts, :users, :preferences
it 'returns correct number of completed todos' do
contexts(:call).should_not have(:any).done_todos
contexts(:call).done_todos.should_not have(:any).items
contexts(:call).todos.first.complete!
contexts(:call).should have(1).done_todos
Context.find(contexts(:call).id).done_todos.should have(1).items
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
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

View file

@ -1,19 +0,0 @@
class ContextsScenario < Scenario::Base
uses :users
def load
%w(Call Email Errand Someday).each_with_index do |context, index|
create_context context, index+1
end
end
def create_context(name, position)
create_model :context, name.downcase.to_sym,
:name => name,
:position => position,
:hide => name == 'Someday' ? true : false,
:created_at => Time.now,
:updated_at => Time.now,
:user_id => user_id(:sean)
end
end

View file

@ -1,20 +0,0 @@
class ProjectsScenario < Scenario::Base
def load
create_project :build_time_machine, 'Build a working time machine'
create_project :make_more_money, 'Make more money than Billy Gates'
create_project :evict_dinosaurs, 'Evict dinosaurs from the garden'
create_project :attend_railsconf, 'Attend RailsConf'
end
def create_project(identifier, name)
attributes = {
:name => name,
:state => 'active',
:created_at => 4.day.ago,
:updated_at => 1.minute.ago
}
create_model :project,
identifier || attributes[:name].split.first.downcase.to_sym,
attributes
end
end

View file

@ -1,30 +0,0 @@
class TodosScenario < Scenario::Base
uses :contexts, :projects, :users
def load
create_todo :bill,
:description => 'Call Bill Gates to find out how much he makes per day',
:user => :sean,
:context => :call,
:project => :make_more_money
create_todo :bank,
:description => 'Call my bank',
:user => :sean,
:context => :call,
:project => :make_more_money
end
def create_todo(identifier, options={})
context = options.delete(:context)
project = options.delete(:project)
user = options.delete(:user)
attributes = {
:state => 'active',
:created_at => 1.week.ago,
:context_id => context_id(context),
:project_id => project_id(project),
:user_id => user_id(user)
}.merge(options)
create_model :todo, identifier, attributes
end
end

View file

@ -1,19 +0,0 @@
class UsersScenario < Scenario::Base
def load
create_user :login => 'johnny', :first_name => 'Johnny', :last_name => 'Smith'
create_user :login => 'jane', :first_name => 'Jane', :last_name => 'Pilbeam'
create_user :login => 'sean', :first_name => 'Sean', :last_name => 'Pallmer'
end
def create_user(attributes={})
password = attributes[:login] + Time.now.to_s
attributes = {
:password => password,
:password_confirmation => password,
:is_admin => attributes[:is_admin] || false,
}.merge(attributes)
identifier = attributes[:login].downcase.to_sym
user = create_model :user, identifier, attributes
Preference.create(:show_number_completed => 5, :user => user)
end
end

View file

@ -5,7 +5,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec'
require 'spec/rails'
require 'skinny_spec'
require 'scenarios'
module LuckySneaks
module ModelSpecHelpers