Skip to content

Commit b91bd81

Browse files
committed
Remove factory girl completely #WIP_169
1 parent 367d998 commit b91bd81

15 files changed

+106
-157
lines changed

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ group :development do
148148
end
149149

150150
group :development, :test do
151-
gem 'factory_girl_rails'
151+
gem 'fabrication-rails'
152152
gem 'ffaker'
153153
gem 'jazz_hands', github: 'nixme/jazz_hands', branch: 'bring-your-own-debugger'
154154
gem 'launchy'
@@ -162,7 +162,6 @@ gem 'mail_view'
162162
group :test do
163163
gem 'capybara', '~> 1.1'
164164
gem 'database_cleaner'
165-
gem 'fabrication', '1.4.1'
166165
gem 'fuubar'
167166
gem 'resque_spec'
168167
gem 'rspec-rails'

Gemfile.lock

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,10 @@ GEM
181181
excon (0.32.0)
182182
execjs (1.4.0)
183183
multi_json (~> 1.0)
184-
fabrication (1.4.1)
185-
factory_girl (4.4.0)
186-
activesupport (>= 3.0.0)
187-
factory_girl_rails (4.4.1)
188-
factory_girl (~> 4.4.0)
189-
railties (>= 3.0.0)
184+
fabrication (2.11.3)
185+
fabrication-rails (0.0.1)
186+
fabrication
187+
railties (>= 3.0)
190188
fakefs (0.4.2)
191189
faraday (0.8.9)
192190
multipart-post (~> 1.2.0)
@@ -642,8 +640,7 @@ DEPENDENCIES
642640
database_cleaner
643641
dotenv-rails
644642
ember-rails!
645-
fabrication (= 1.4.1)
646-
factory_girl_rails
643+
fabrication-rails
647644
faraday (~> 0.8.1)
648645
feedjira
649646
ffaker

app/models/comment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Comment < ActiveRecord::Base
4242

4343
default_scope order: 'likes_cache DESC, created_at ASC'
4444

45-
belongs_to :user
45+
belongs_to :user, autosave: true
4646

4747
alias_method :author, :user
4848
alias_attribute :body, :comment

app/models/protip.rb

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Protip < ActiveRecord::Base
118118
has_many :likes, as: :likable, dependent: :destroy, after_add: :reset_likes_cache, after_remove: :reset_likes_cache
119119
has_many :protip_links, autosave: true, dependent: :destroy, after_add: :reset_links_cache, after_remove: :reset_links_cache
120120
has_one :spam_report, as: :spammable
121-
belongs_to :user
121+
belongs_to :user , autosave: true
122122

123123
rakismet_attrs author: proc { self.user.name },
124124
author_email: proc { self.user.email },
@@ -1075,88 +1075,4 @@ def analyze_spam
10751075
Resque.enqueue(AnalyzeSpam, { id: id, klass: self.class.name })
10761076
end
10771077

1078-
class SearchWrapper
1079-
attr_reader :item
1080-
1081-
def initialize(item)
1082-
@item = item.is_a?(Protip) ? item.to_public_hash : item
1083-
end
1084-
1085-
def username
1086-
item[:user][:username]
1087-
end
1088-
1089-
def profile_url
1090-
avatar
1091-
end
1092-
1093-
def avatar
1094-
item[:user][:avatar]
1095-
end
1096-
1097-
def already_voted?(current_user, tracking, ip_address)
1098-
false
1099-
end
1100-
1101-
def user
1102-
self #proxy user calls to self
1103-
end
1104-
1105-
def owner?(user)
1106-
return false if user.nil?
1107-
username == user.username
1108-
end
1109-
1110-
def upvotes
1111-
item[:upvotes]
1112-
end
1113-
1114-
def topics
1115-
(item[:tags] - [item[:user][:username]]).uniq
1116-
end
1117-
1118-
def only_link?
1119-
item[:only_link] == true
1120-
end
1121-
1122-
def link
1123-
item[:link]
1124-
end
1125-
1126-
def title
1127-
item[:title]
1128-
end
1129-
1130-
def to_s
1131-
public_id #for url creation
1132-
end
1133-
1134-
def public_id
1135-
item[:public_id]
1136-
end
1137-
1138-
def created_at
1139-
item[:created_at]
1140-
end
1141-
1142-
def self.model_name
1143-
Protip.model_name
1144-
end
1145-
1146-
def viewed_by?(viewer)
1147-
singleton.viewed_by?(viewer)
1148-
end
1149-
1150-
def total_views
1151-
singleton.total_views
1152-
end
1153-
1154-
def team_profile_url
1155-
item[:team][:profile_url]
1156-
end
1157-
1158-
def singleton
1159-
item.is_a?(Protip) ? item : Protip.new(public_id: public_id)
1160-
end
1161-
end
11621078
end

app/models/protip/search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Search < SearchModule::Search
1+
class Protip::Search < SearchModule::Search
22

33
def failover_strategy
44
{failover: Protip.order('score DESC')}

app/models/protip/search/query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Query < SearchModule::Search::Query
1+
class Protip::Search::Query < SearchModule::Search::Query
22
def default_query
33
"flagged:false"
44
end

app/models/protip/search/scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Scope < SearchModule::Search::Scope
1+
class Protip::Search::Scope < SearchModule::Search::Scope
22

33
def to_hash
44
case @domain

app/models/protip/search_wrapper.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
class Protip::SearchWrapper
2+
attr_reader :item
3+
4+
def initialize(item)
5+
@item = item.is_a?(Protip) ? item.to_public_hash : item
6+
end
7+
8+
def username
9+
item[:user][:username]
10+
end
11+
12+
def profile_url
13+
avatar
14+
end
15+
16+
def avatar
17+
item[:user][:avatar]
18+
end
19+
20+
def already_voted?(current_user, tracking, ip_address)
21+
false
22+
end
23+
24+
def user
25+
self #proxy user calls to self
26+
end
27+
28+
def owner?(user)
29+
return false if user.nil?
30+
username == user.username
31+
end
32+
33+
def upvotes
34+
item[:upvotes]
35+
end
36+
37+
def topics
38+
(item[:tags] - [item[:user][:username]]).uniq
39+
end
40+
41+
def only_link?
42+
item[:only_link] == true
43+
end
44+
45+
def link
46+
item[:link]
47+
end
48+
49+
def title
50+
item[:title]
51+
end
52+
53+
def to_s
54+
public_id #for url creation
55+
end
56+
57+
def public_id
58+
item[:public_id]
59+
end
60+
61+
def created_at
62+
item[:created_at]
63+
end
64+
65+
def self.model_name
66+
Protip.model_name
67+
end
68+
69+
def viewed_by?(viewer)
70+
singleton.viewed_by?(viewer)
71+
end
72+
73+
def total_views
74+
singleton.total_views
75+
end
76+
77+
def team_profile_url
78+
item[:team][:profile_url]
79+
end
80+
81+
def singleton
82+
item.is_a?(Protip) ? item : Protip.new(public_id: public_id)
83+
end
84+
end

config/application.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ class Application < Rails::Application
2424
config.encoding = 'utf-8'
2525

2626
config.filter_parameters += [:password]
27-
config.generators do |g|
28-
g.test_framework :rspec, fixture: true
29-
g.fixture_replacement :factory_girl
30-
g.orm :active_record
31-
end
27+
3228

3329
config.ember.variant = Rails.env.downcase.to_sym
3430
config.assets.js_compressor = :uglifier
@@ -38,7 +34,6 @@ class Application < Rails::Application
3834

3935
config.after_initialize do
4036
if %w{development test}.include?(Rails.env)
41-
include FactoryGirl::Syntax::Methods
4237
Hirb.enable
4338
end
4439
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Fabricator(:comment) do
22
comment { 'Lorem Ipsum is simply dummy text...' }
3-
commentable! { Fabricate(:protip) }
3+
commentable { Fabricate.build(:protip) }
4+
user { Fabricate.build(:user) }
45
end

spec/fabricators/fact_fabricator.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@
2626
# * **`owner`**
2727
#
2828

29-
Fabricator(:fact) do
29+
Fabricator(:fact, from: 'fact') do
3030
context { Fabricate(:user) }
3131
end
3232

3333
Fabricator(:lanyrd_original_fact, from: :fact) do
34-
owner { |fact| fact.context.lanyrd_identity }
34+
owner { |fact| fact[:context].lanyrd_identity }
3535
url { Faker::Internet.domain_name }
36-
identity { |fact| "/#{rand(1000)}/speakerconf/:" + fact.context.lanyrd_identity }
36+
identity { |fact| "/#{rand(1000)}/speakerconf/:" + fact[:owner] }
3737
name { Faker::Company.catch_phrase }
3838
relevant_on { rand(100).days.ago }
3939
tags { ['lanyrd', 'event', 'spoke', 'Software', 'Ruby'] }
4040
end
4141

4242
Fabricator(:github_original_fact, from: :fact) do
43-
owner { |fact| fact.context.github_identity }
43+
owner { |fact| fact[:context].github_identity }
4444
url { Faker::Internet.domain_name }
45-
identity { |fact| fact.url + ':' + fact.context.github_identity }
45+
identity { |fact| fact[:url] + ':' + fact[:owner] }
4646
name { Faker::Company.catch_phrase }
4747
relevant_on { rand(100).days.ago }
4848
metadata { {

spec/fabricators/protip_fabricator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
topics ["Javascript", "CoffeeScript"]
3636
title { Faker::Company.catch_phrase }
3737
body { Faker::Lorem.sentences(8).join(' ') }
38-
user { Fabricate(:user) }
38+
user { Fabricate.build(:user) }
3939
end
4040

4141
Fabricator(:link_protip, from: :protip) do

spec/factories.rb

Lines changed: 0 additions & 40 deletions
This file was deleted.

spec/jobs/analyze_spam_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
context 'when it is a spam' do
44
it 'should create a spam report' do
55
Comment.any_instance.stub(:spam?).and_return(true)
6-
spammable = create(:comment)
6+
spammable = Fabricate(:comment)
77
AnalyzeSpam.new(id: spammable.id, klass: spammable.class.name).perform
88
spammable.spam_report.should_not be_nil
99
end
@@ -12,7 +12,7 @@
1212
context 'when it is not a spam' do
1313
it 'should not create a spam report' do
1414
Comment.any_instance.stub(:spam?).and_return(false)
15-
spammable = create(:comment)
15+
spammable = Fabricate(:comment)
1616
AnalyzeSpam.new(id: spammable.id, klass: spammable.class.name).perform
1717
spammable.spam_report.should be_nil
1818
end

spec/spec_helper.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
RSpec.configure do |config|
2121
config.treat_symbols_as_metadata_keys_with_true_values = true
2222

23-
config.include FactoryGirl::Syntax::Methods
24-
2523
config.mock_with :rspec
2624
config.use_transactional_fixtures = false
2725
config.use_transactional_examples = false
@@ -33,7 +31,6 @@
3331
end
3432

3533
config.before(:suite) do
36-
FactoryGirl.lint
3734

3835
DatabaseCleaner.strategy = :transaction
3936
DatabaseCleaner.clean_with(:truncation)

0 commit comments

Comments
 (0)