|
| 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 | + |
0 commit comments