Skip to content

Commit 1d01804

Browse files
committed
First steps to moving to Rspec
1 parent b636cd5 commit 1d01804

9 files changed

+408
-14
lines changed

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.2

Appraisals

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ end
88

99
appraise "activerecord32" do
1010
gem "activerecord", "~> 3.2.1"
11-
end
11+
end
12+
13+
appraise "activerecord40" do
14+
gem "activerecord", "~> 4.0.13"
15+
end
16+
17+
appraise "activerecord41" do
18+
gem "activerecord", "~> 4.1.12"
19+
end
20+
21+
appraise "activerecord42" do
22+
gem "activerecord", "~> 4.2.3"
23+
end

Guardfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
guard :rspec, cmd: "bundle exec rspec" do
2+
require "guard/rspec/dsl"
3+
dsl = Guard::RSpec::Dsl.new(self)
4+
5+
rspec = dsl.rspec
6+
watch(rspec.spec_helper) { rspec.spec_dir }
7+
watch(rspec.spec_support) { rspec.spec_dir }
8+
watch(rspec.spec_files)
9+
10+
ruby = dsl.ruby
11+
dsl.watch_spec_files_for(ruby.lib_files)
12+
end

Rakefile

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
require 'rake'
2-
require 'rake/testtask'
32
require 'bundler/gem_tasks'
43
require 'appraisal'
54

6-
desc 'Default: run unit tests against all supported versions of ActiveRecord'
7-
task :default => ["appraisal:install"] do |t|
8-
exec("rake appraisal test")
9-
end
5+
begin
6+
require 'rspec/core/rake_task'
7+
RSpec::Core::RakeTask.new(:spec)
108

11-
desc 'Test the socialization plugin.'
12-
Rake::TestTask.new(:test) do |t|
13-
t.libs << 'lib'
14-
t.pattern = 'test/**/*_test.rb'
15-
t.verbose = true
9+
desc 'Default: run unit tests against all supported versions of ActiveRecord'
10+
task :default => ["appraisal:install"] do |t|
11+
exec("rake appraisal spec")
12+
end
13+
rescue LoadError
1614
end

socialization.gemspec

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Gem::Specification.new do |s|
2222

2323
s.add_development_dependency "appraisal"
2424
s.add_development_dependency "logger"
25-
s.add_development_dependency "mocha"
26-
s.add_development_dependency "shoulda"
25+
s.add_development_dependency "rspec", "~> 3.3.0"
2726
s.add_development_dependency "sqlite3"
2827
s.add_development_dependency "yard"
2928
s.add_development_dependency "mock_redis"
30-
end
29+
s.add_development_dependency "guard"
30+
s.add_development_dependency "guard-rspec"
31+
end

spec/spec_helper.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$MOCK_REDIS = true
2+
3+
require 'bundler/setup'
4+
Bundler.setup
5+
6+
RSpec.configure do |config|
7+
config.expect_with(:rspec) { |c| c.syntax = :expect }
8+
end
9+
10+
$:.push File.expand_path("../lib", __FILE__)
11+
require 'active_record'
12+
require "socialization"
13+
require 'spec_helpers/data_stores'
14+
require 'logger'
15+
16+
ActiveSupport::Inflector.inflections do |inflect|
17+
inflect.irregular 'cache', 'caches'
18+
end

spec/spec_helpers/data_stores.rb

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
require 'mock_redis' if $MOCK_REDIS
2+
require 'redis' unless $MOCK_REDIS
3+
4+
silence_warnings do
5+
Redis = MockRedis if $MOCK_REDIS # Magic!
6+
end
7+
8+
def use_redis_store
9+
Socialization.follow_model = Socialization::RedisStores::Follow
10+
Socialization.mention_model = Socialization::RedisStores::Mention
11+
Socialization.like_model = Socialization::RedisStores::Like
12+
setup_model_shortcuts
13+
end
14+
15+
def use_ar_store
16+
Socialization.follow_model = Socialization::ActiveRecordStores::Follow
17+
Socialization.mention_model = Socialization::ActiveRecordStores::Mention
18+
Socialization.like_model = Socialization::ActiveRecordStores::Like
19+
setup_model_shortcuts
20+
end
21+
22+
def setup_model_shortcuts
23+
$Follow = Socialization.follow_model
24+
$Mention = Socialization.mention_model
25+
$Like = Socialization.like_model
26+
end
27+
28+
def clear_redis
29+
Socialization.redis.keys(nil).each do |k|
30+
Socialization.redis.del k
31+
end
32+
end
33+
34+
ActiveRecord::Base.configurations = {'sqlite3' => {:adapter => 'sqlite3', :database => ':memory:'}}
35+
ActiveRecord::Base.establish_connection(:sqlite3)
36+
37+
ActiveRecord::Base.logger = Logger.new(STDERR)
38+
ActiveRecord::Base.logger.level = Logger::WARN
39+
40+
ActiveRecord::Migration.verbose = false
41+
ActiveRecord::Schema.define(:version => 0) do
42+
create_table :users do |t|
43+
t.string :name
44+
end
45+
46+
create_table :celebrities do |t|
47+
t.string :name
48+
end
49+
50+
create_table :movies do |t|
51+
t.string :name
52+
end
53+
54+
create_table :comments do |t|
55+
t.integer :user_id
56+
t.integer :movie_id
57+
t.string :body
58+
end
59+
60+
create_table :follows do |t|
61+
t.string :follower_type
62+
t.integer :follower_id
63+
t.string :followable_type
64+
t.integer :followable_id
65+
t.datetime :created_at
66+
end
67+
68+
create_table :likes do |t|
69+
t.string :liker_type
70+
t.integer :liker_id
71+
t.string :likeable_type
72+
t.integer :likeable_id
73+
t.datetime :created_at
74+
end
75+
76+
create_table :mentions do |t|
77+
t.string :mentioner_type
78+
t.integer :mentioner_id
79+
t.string :mentionable_type
80+
t.integer :mentionable_id
81+
t.datetime :created_at
82+
end
83+
84+
create_table :im_a_followers do |t|
85+
t.timestamps null: true
86+
end
87+
88+
create_table :im_a_follower_with_counter_caches do |t|
89+
t.integer :followees_count, default: 0
90+
t.timestamps null: true
91+
end
92+
93+
create_table :im_a_followables do |t|
94+
t.timestamps null: true
95+
end
96+
97+
create_table :im_a_followable_with_counter_caches do |t|
98+
t.integer :followers_count, default: 0
99+
t.timestamps null: true
100+
end
101+
102+
create_table :im_a_likers do |t|
103+
t.timestamps null: true
104+
end
105+
106+
create_table :im_a_liker_with_counter_caches do |t|
107+
t.integer :likees_count, default: 0
108+
t.timestamps null: true
109+
end
110+
111+
create_table :im_a_likeables do |t|
112+
t.timestamps null: true
113+
end
114+
115+
create_table :im_a_likeable_with_counter_caches do |t|
116+
t.integer :likers_count, default: 0
117+
t.timestamps null: true
118+
end
119+
120+
create_table :im_a_mentioners do |t|
121+
t.timestamps null: true
122+
end
123+
124+
create_table :im_a_mentioner_with_counter_caches do |t|
125+
t.integer :mentionees_count, default: 0
126+
t.timestamps null: true
127+
end
128+
129+
create_table :im_a_mentionables do |t|
130+
t.timestamps null: true
131+
end
132+
133+
create_table :im_a_mentionable_with_counter_caches do |t|
134+
t.integer :mentioners_count, default: 0
135+
t.timestamps null: true
136+
end
137+
138+
create_table :im_a_mentioner_and_mentionables do |t|
139+
t.timestamps null: true
140+
end
141+
142+
create_table :vanillas do |t|
143+
t.timestamps null: true
144+
end
145+
end
146+
147+
class Celebrity < ActiveRecord::Base
148+
acts_as_followable
149+
acts_as_mentionable
150+
end
151+
152+
class User < ActiveRecord::Base
153+
acts_as_follower
154+
acts_as_followable
155+
acts_as_liker
156+
acts_as_likeable
157+
acts_as_mentionable
158+
159+
has_many :comments
160+
end
161+
162+
class Comment < ActiveRecord::Base
163+
acts_as_mentioner
164+
belongs_to :user
165+
belongs_to :movie
166+
end
167+
168+
class Movie < ActiveRecord::Base
169+
acts_as_likeable
170+
has_many :comments
171+
end
172+
173+
# class Follow < Socialization::ActiveRecordStores::Follow; end
174+
# class Like < Socialization::ActiveRecordStores::Like; end
175+
# class Mention < Socialization::ActiveRecordStores::Mention; end
176+
177+
class ImAFollower < ActiveRecord::Base
178+
acts_as_follower
179+
end
180+
class ImAFollowerWithCounterCache < ActiveRecord::Base
181+
acts_as_follower
182+
end
183+
class ImAFollowerChild < ImAFollower; end
184+
185+
class ImAFollowable < ActiveRecord::Base
186+
acts_as_followable
187+
end
188+
class ImAFollowableWithCounterCache < ActiveRecord::Base
189+
acts_as_followable
190+
end
191+
class ImAFollowableChild < ImAFollowable; end
192+
193+
class ImALiker < ActiveRecord::Base
194+
acts_as_liker
195+
end
196+
class ImALikerWithCounterCache < ActiveRecord::Base
197+
acts_as_liker
198+
end
199+
class ImALikerChild < ImALiker; end
200+
201+
class ImALikeable < ActiveRecord::Base
202+
acts_as_likeable
203+
end
204+
class ImALikeableWithCounterCache < ActiveRecord::Base
205+
acts_as_likeable
206+
end
207+
class ImALikeableChild < ImALikeable; end
208+
209+
class ImAMentioner < ActiveRecord::Base
210+
acts_as_mentioner
211+
end
212+
class ImAMentionerWithCounterCache < ActiveRecord::Base
213+
acts_as_mentioner
214+
end
215+
class ImAMentionerChild < ImAMentioner; end
216+
217+
class ImAMentionable < ActiveRecord::Base
218+
acts_as_mentionable
219+
end
220+
class ImAMentionableWithCounterCache < ActiveRecord::Base
221+
acts_as_mentionable
222+
end
223+
class ImAMentionableChild < ImAMentionable; end
224+
225+
class ImAMentionerAndMentionable < ActiveRecord::Base
226+
acts_as_mentioner
227+
acts_as_mentionable
228+
end
229+
230+
class Vanilla < ActiveRecord::Base
231+
end
232+

spec/string_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'spec_helper'
2+
3+
describe String do
4+
describe "#deep_const_get" do
5+
it "should return a class" do
6+
expect("Socialization".deep_const_get).to eq(Socialization)
7+
expect("Socialization::ActiveRecordStores".deep_const_get).to eq(Socialization::ActiveRecordStores)
8+
expect("Socialization::ActiveRecordStores::Follow".deep_const_get).to eq(Socialization::ActiveRecordStores::Follow)
9+
10+
expect { "Foo::Bar".deep_const_get }.to raise_error(NameError)
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)