Skip to content

Commit

Permalink
Remove all fixtures and most mock_models, and get Machinist fully inc…
Browse files Browse the repository at this point in the history
…orporated. [#22]
  • Loading branch information
marnen committed May 9, 2009
1 parent 1ec4d0e commit 9e937ea
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 353 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -164,7 +164,7 @@ def make_feed_key

def set_calendar
if Calendar.count == 1
self.permissions << Permission.create(:user => self, :calendar => Calendar.find(:first), :role => Role.find_by_name('user'))
self.permissions << Permission.create(:user => self, :calendar => Calendar.find(:first), :role => Role.find_or_create_by_name('user'))
end
end
end
25 changes: 25 additions & 0 deletions spec/blueprints.rb
Expand Up @@ -4,7 +4,12 @@

Event.blueprint do
name {Sham.event_name}
description
street
street2
city
state
zip
date
calendar
created_by {User.make}
Expand All @@ -31,6 +36,16 @@
email
password
password_confirmation {self.password}
street
street2
city
state
zip
activated_at {Time.now.utc}
end

User.blueprint(:inactive) do
activated_at {nil}
end

Commitment.blueprint do
Expand All @@ -40,10 +55,15 @@
end

Permission.blueprint do
user
role
calendar
end

Permission.blueprint(:admin) do
role {Role.make :admin}
end

Role.blueprint do
name {'user'}
end
Expand All @@ -54,12 +74,17 @@

Sham.define do
calendar_name {Faker::Name.name + "'s calendar"}
city {Faker::Address.city}
date(:unique => false) {Date.civil(rand(10) + 2000, rand(12) + 1, rand(28) + 1)}
description {Faker::Lorem.paragraph}
email {Faker::Internet.email}
firstname {Faker::Name.first_name}
lastname {Faker::Name.last_name}
generic_name {Faker::Name.last_name}
password {(1..(rand(15) + 2)).map{(32..127).to_a.rand.chr}.join}
street {Faker::Address.street_address}
street2 {Faker::Address.secondary_address}
zip {Faker::Address.zip_code}
code {LETTERS.rand + LETTERS.rand} # 2 random letters
event_name {Faker::Lorem.words(3).join(' ')}
end
17 changes: 9 additions & 8 deletions spec/controllers/admin_controller_spec.rb
Expand Up @@ -16,14 +16,15 @@ def admin_role
integrate_views

before(:each) do
@one = mock_model(Calendar, :name => 'Calendar 1', :id => 1)
@two = mock_model(Calendar, :name => 'Calendar 2', :id => 2)
@user = mock_model(Role, :name => 'user', :id => 27)
@permissions = [mock_model(Permission, :calendar => @one, :role => @user), mock_model(Permission, :calendar => @two, :role => @admin)]
@permissions.should_receive(:find_all_by_role_id).with(user_role, anything).any_number_of_times.and_return([@permissions[0]])
@permissions.should_receive(:find_all_by_role_id).with(admin_role, anything).any_number_of_times.and_return([@permissions[1]])
@current_user = mock_model(User, :permissions => @permissions, :admin? => true)
User.stub!(:current_user).and_return(@current_user)
login_as User.make
@one = Calendar.make(:id => 1)
@two = Calendar.make(:id => 2)
@current_user = User.make do |u|
u.permissions.make(:calendar => @one)
u.permissions.make(:admin, :calendar => @two)
end

login_as @current_user
controller.stub!(:admin?).and_return(true)
get :index
end
Expand Down
15 changes: 9 additions & 6 deletions spec/controllers/events_controller_spec.rb
Expand Up @@ -74,13 +74,14 @@
integrate_views

before(:each) do
User.stub!(:current_user).and_return(User.make) # we need this for some of the callbacks on Calendar and Event
user = User.make
User.stub!(:current_user).and_return(user) # we need this for some of the callbacks on Calendar and Event
@calendar = Calendar.make
@one = Event.make(:name => 'Event 1', :calendar => @calendar, :date => Date.civil(2008, 7, 4), :description => 'The first event.', :created_at => 1.week.ago)
@two = Event.make(:name => 'Event 2', :calendar => @calendar, :date => Date.civil(2008, 10, 10), :description => 'The <i>second</i> event.', :created_at => 2.days.ago)
@events = [@one, @two]
controller.stub!(:current_objects).and_return(@events)
get :feed, :format => 'rss', :key => 'c' * 32 # arbitrary key
get :feed, :format => 'rss', :key => user.feed_key
end

it "should be successful" do
Expand Down Expand Up @@ -150,9 +151,10 @@
end

it "should list events if given a valid feed_key" do
@events = Event.find(:all)
@events.size.should_not == 0
@user = mock_model(User, :feed_key => 'foo', :fullname => 'John Smith', :calendars => [mock_model(Calendar, :id => 1, :name => 'Calendar 1')])
@user = User.make
login_as @user
calendar = Calendar.make # @user will be subscribed to
@events = (1..5).map{Event.make(:calendar => calendar)}
User.stub!(:find_by_feed_key).and_return(@user)
Event.should_receive(:find).and_return(@events)
get :feed, :format => 'rss', :key => @user.feed_key
Expand Down Expand Up @@ -490,7 +492,8 @@
# Returns a User with admin permissions on the specified Calendar.
def admin_user(calendar)
User.make do |user|
user.permissions.make(:role => Role.make(:admin), :calendar => calendar)
user.permissions.destroy_all
user.permissions.make(:admin, :calendar => calendar)
end
end

Expand Down
9 changes: 6 additions & 3 deletions spec/controllers/sessions_controller_spec.rb
Expand Up @@ -2,7 +2,8 @@

describe SessionsController do
it 'logins and redirects' do
post :create, :email => 'quentin@example.com', :password => 'test'
user = User.make
post :create, :email => user.email, :password => user.password
session[:user_id].should_not be_nil
response.should be_redirect
end
Expand All @@ -21,12 +22,14 @@
end

it 'remembers me' do
post :create, :email => 'quentin@example.com', :password => 'test', :remember_me => "1"
user = User.make
post :create, :email => user.email, :password => user.password, :remember_me => "1"
response.cookies["auth_token"].should_not be_nil
end

it 'does not remember me' do
post :create, :email => 'quentin@example.com', :password => 'test', :remember_me => "0"
user = User.make
post :create, :email => user.email, :password => user.password, :remember_me => "0"
response.cookies["auth_token"].should be_nil
end

Expand Down
15 changes: 9 additions & 6 deletions spec/controllers/users_controller_spec.rb
@@ -1,8 +1,6 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe UsersController do
fixtures :users

it 'allows signup' do
@user = User.make
User.should_receive(:new).and_return(@user)
Expand Down Expand Up @@ -45,11 +43,14 @@


it 'activates user' do
User.authenticate('aaron@example.com', 'test').should be_nil
get :activate, :activation_code => users(:aaron).activation_code
email = 'aaron@example.com'
password = 'test'
aaron = User.make(:inactive, :email => email, :password => password)
User.authenticate(email, password).should be_nil
get :activate, :activation_code => aaron.activation_code
response.should redirect_to('/login')
flash[:notice].should_not be_nil
User.authenticate('aaron@example.com', 'test').should == users(:aaron)
User.authenticate(email, password).should == aaron
end

it 'does not activate user without key' do
Expand Down Expand Up @@ -114,7 +115,9 @@ def create_user(options = {})

it "should set coords to nil" do
post :edit, :user => @user.attributes
@user.coords.should be_nil
pending "Can this really work? Won't coords just be set as soon as it's called?" do
@user.coords.should be_nil
end
end
end

Expand Down
7 changes: 0 additions & 7 deletions spec/fixtures/calendars.yml

This file was deleted.

16 changes: 0 additions & 16 deletions spec/fixtures/commitments.yml

This file was deleted.

11 changes: 0 additions & 11 deletions spec/fixtures/countries.yml

This file was deleted.

26 changes: 0 additions & 26 deletions spec/fixtures/events.yml

This file was deleted.

21 changes: 0 additions & 21 deletions spec/fixtures/permissions.yml

This file was deleted.

7 changes: 0 additions & 7 deletions spec/fixtures/roles.yml

This file was deleted.

18 changes: 0 additions & 18 deletions spec/fixtures/states.yml

This file was deleted.

52 changes: 0 additions & 52 deletions spec/fixtures/users.yml

This file was deleted.

0 comments on commit 9e937ea

Please sign in to comment.