Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from factory girls to Fabrication Gem #134

Merged
merged 17 commits into from
Nov 30, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ gem 'ri_cal'
group :development, :test do
gem 'rspec-rails', '~> 2.6'
gem 'webmock', :require => false
gem 'factory_girl', '~> 1.3.3'
gem 'factory_girl_rails', '~> 1.0.1'
gem 'fabrication'
unless ENV['TRAVIS']
gem 'ruby-debug', :platform => :mri_18
gem 'ruby-debug19', :platform => :mri_19, :require => 'ruby-debug'
Expand Down
8 changes: 2 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ GEM
rspec (~> 2.0)
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (1.3.3)
factory_girl_rails (1.0.1)
factory_girl (~> 1.3)
railties (>= 3.0.0)
fabrication (1.2.0)
faraday (0.7.4)
addressable (~> 2.2.6)
multipart-post (~> 1.1.0)
Expand Down Expand Up @@ -219,8 +216,7 @@ DEPENDENCIES
database_cleaner (~> 0.6.0)
devise (~> 1.4.0)
email_spec
factory_girl (~> 1.3.3)
factory_girl_rails (~> 1.0.1)
fabrication
haml
hoptoad_notifier (~> 2.4)
htmlentities (~> 4.3.0)
Expand Down
4 changes: 3 additions & 1 deletion app/models/problem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def cache_app_attributes
self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last)
last_deploy.created_at
end
self.save if persisted?
collection.update({'_id' => self.id},
{'$set' => {'app_name' => self.app_name,
'last_deploy_at' => self.last_deploy_at}})
end
end

Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Application < Rails::Application
g.orm :mongoid
g.template_engine :haml
g.test_framework :rspec, :fixture => false
g.fixture_replacement :fabrication
end

# IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode.
Expand Down
56 changes: 28 additions & 28 deletions spec/controllers/apps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
describe "GET /apps" do
context 'when logged in as an admin' do
it 'finds all apps' do
sign_in Factory(:admin)
3.times { Factory(:app) }
sign_in Fabricate(:admin)
3.times { Fabricate(:app) }
apps = App.all
get :index
assigns(:apps).should == apps
Expand All @@ -20,12 +20,12 @@

context 'when logged in as a regular user' do
it 'finds apps the user is watching' do
sign_in(user = Factory(:user))
unwatched_app = Factory(:app)
watched_app1 = Factory(:app)
watched_app2 = Factory(:app)
Factory(:user_watcher, :user => user, :app => watched_app1)
Factory(:user_watcher, :user => user, :app => watched_app2)
sign_in(user = Fabricate(:user))
unwatched_app = Fabricate(:app)
watched_app1 = Fabricate(:app)
watched_app2 = Fabricate(:app)
Fabricate(:user_watcher, :user => user, :app => watched_app1)
Fabricate(:user_watcher, :user => user, :app => watched_app2)
get :index
assigns(:apps).should include(watched_app1, watched_app2)
assigns(:apps).should_not include(unwatched_app)
Expand All @@ -36,10 +36,10 @@
describe "GET /apps/:id" do
context 'logged in as an admin' do
before(:each) do
@user = Factory(:admin)
@user = Fabricate(:admin)
sign_in @user
@app = Factory(:app)
@problem = Factory(:notice, :err => Factory(:err, :problem => Factory(:problem, :app => @app))).problem
@app = Fabricate(:app)
@problem = Fabricate(:notice, :err => Fabricate(:err, :problem => Fabricate(:problem, :app => @app))).problem
end

it 'finds the app' do
Expand All @@ -48,7 +48,7 @@
end

it "should not raise errors for app with err without notices" do
Factory(:err, :problem => Factory(:problem, :app => @app))
Fabricate(:err, :problem => Fabricate(:problem, :app => @app))
lambda { get :show, :id => @app.id }.should_not raise_error
end

Expand All @@ -60,7 +60,7 @@

context "pagination" do
before(:each) do
35.times { Factory(:err, :problem => Factory(:problem, :app => @app)) }
35.times { Fabricate(:err, :problem => Fabricate(:problem, :app => @app)) }
end

it "should have default per_page value for user" do
Expand All @@ -77,8 +77,8 @@

context 'with resolved errors' do
before(:each) do
resolved_problem = Factory(:problem, :app => @app)
Factory(:notice, :err => Factory(:err, :problem => resolved_problem))
resolved_problem = Fabricate(:problem, :app => @app)
Fabricate(:notice, :err => Fabricate(:err, :problem => resolved_problem))
resolved_problem.resolve!
end

Expand All @@ -101,7 +101,7 @@
before(:each) do
environments = ['production', 'test', 'development', 'staging']
20.times do |i|
Factory.create(:problem, :app => @app, :environment => environments[i % environments.length])
Fabricate(:problem, :app => @app, :environment => environments[i % environments.length])
end
end

Expand Down Expand Up @@ -144,17 +144,17 @@

context 'logged in as a user' do
it 'finds the app if the user is watching it' do
user = Factory(:user)
app = Factory(:app)
watcher = Factory(:user_watcher, :app => app, :user => user)
user = Fabricate(:user)
app = Fabricate(:app)
watcher = Fabricate(:user_watcher, :app => app, :user => user)
sign_in user
get :show, :id => app.id
assigns(:app).should == app
end

it 'does not find the app if the user is not watching it' do
sign_in Factory(:user)
app = Factory(:app)
sign_in Fabricate(:user)
app = Fabricate(:app)
lambda {
get :show, :id => app.id
}.should raise_error(Mongoid::Errors::DocumentNotFound)
Expand All @@ -164,7 +164,7 @@

context 'logged in as an admin' do
before do
sign_in Factory(:admin)
sign_in Fabricate(:admin)
end

describe "GET /apps/new" do
Expand All @@ -176,7 +176,7 @@
end

it "should copy attributes from an existing app" do
@app = Factory(:app, :name => "do not copy",
@app = Fabricate(:app, :name => "do not copy",
:github_url => "github.com/test/example")
get :new, :copy_attributes_from => @app.id
assigns(:app).should be_a(App)
Expand All @@ -188,15 +188,15 @@

describe "GET /apps/:id/edit" do
it 'finds the correct app' do
app = Factory(:app)
app = Fabricate(:app)
get :edit, :id => app.id
assigns(:app).should == app
end
end

describe "POST /apps" do
before do
@app = Factory(:app)
@app = Fabricate(:app)
App.stub(:new).and_return(@app)
end

Expand All @@ -219,7 +219,7 @@

describe "PUT /apps/:id" do
before do
@app = Factory(:app)
@app = Fabricate(:app)
end

context "when the update is successful" do
Expand Down Expand Up @@ -257,7 +257,7 @@
end
context "failed parsing of CSV" do
it "should set the default value" do
@app = Factory(:app, :email_at_notices => [1, 2, 3, 4])
@app = Fabricate(:app, :email_at_notices => [1, 2, 3, 4])
put :update, :id => @app.id, :app => { :email_at_notices => 'asdf, -1,0,foobar,gd00,0,abc' }
@app.reload
@app.email_at_notices.should == Errbit::Config.email_at_notices
Expand Down Expand Up @@ -320,7 +320,7 @@

describe "DELETE /apps/:id" do
before do
@app = Factory(:app)
@app = Fabricate(:app)
App.stub(:find).with(@app.id).and_return(@app)
end

Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/deploys_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scm_revision' => '19d77837eef37902cf5df7e4445c85f392a8d0d5',
'message' => 'johns first deploy'
}
@app = Factory(:app_with_watcher, :notify_on_deploys => true, :api_key => 'APIKEY')
@app = Fabricate(:app_with_watcher, :notify_on_deploys => true, :api_key => 'APIKEY')
end

it 'finds the app via the api key' do
Expand All @@ -30,7 +30,7 @@
:revision => '19d77837eef37902cf5df7e4445c85f392a8d0d5',
:message => 'johns first deploy'

}).and_return(Factory(:deploy))
}).and_return(Fabricate(:deploy))
post :create, :deploy => @params, :api_key => 'APIKEY'
end

Expand All @@ -45,8 +45,8 @@

context "GET #index" do
before(:each) do
@deploy = Factory :deploy
sign_in Factory(:admin)
@deploy = Fabricate :deploy
sign_in Fabricate(:admin)
get :index, :app_id => @deploy.app.id
end

Expand Down