pose 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +42 -19
- data/Rakefile +37 -5
- data/lib/pose/activerecord_base_additions.rb +7 -6
- data/{app/models → lib}/pose/assignment.rb +6 -1
- data/lib/pose/jobs/install.rb +27 -0
- data/lib/pose/jobs/reindex_all.rb +34 -0
- data/lib/pose/jobs/remove.rb +28 -0
- data/lib/pose/jobs/uninstall.rb +19 -0
- data/lib/pose/jobs/vacuum.rb +23 -0
- data/lib/pose/model_class_additions.rb +32 -14
- data/lib/pose/query.rb +49 -9
- data/lib/pose/search.rb +5 -5
- data/lib/pose/static_api.rb +21 -3
- data/lib/pose/version.rb +1 -1
- data/lib/pose/word.rb +33 -0
- data/lib/pose.rb +11 -5
- data/lib/tasks/pose_tasks.rake +16 -27
- data/spec/{dummy/db/development.sqlite3 → db/pose.sqlite3} +0 -0
- data/spec/factories/posable_one.rb +2 -0
- data/spec/factories/posable_three.rb +8 -0
- data/spec/factories/posable_two.rb +2 -0
- data/spec/factories/user.rb +2 -0
- data/spec/lib/pose/activerecord_base_additions_spec.rb +11 -0
- data/spec/{models → lib/pose}/assignment_spec.rb +5 -5
- data/spec/lib/pose/jobs/reindex_all_spec.rb +31 -0
- data/spec/lib/pose/jobs/remove_spec.rb +20 -0
- data/spec/lib/pose/model_class_additions_spec.rb +150 -0
- data/spec/lib/pose/query_spec.rb +106 -8
- data/spec/lib/pose/search_spec.rb +2 -22
- data/spec/lib/pose/word_spec.rb +68 -0
- data/spec/pose_api_spec.rb +33 -13
- data/spec/spec_helper.rb +4 -32
- data/spec/support/config/database.yml +51 -0
- data/spec/support/config/database.yml.example +16 -0
- data/spec/{dummy/db/migrate → support/migrations}/20130308054001_create_posable_one.rb +0 -0
- data/spec/{dummy/db/migrate → support/migrations}/20130308054142_create_posable_two.rb +0 -0
- data/spec/support/migrations/20130308054143_create_posable_three.rb +9 -0
- data/spec/{dummy/db/migrate → support/migrations}/20130708084009_create_users.rb +0 -0
- data/spec/support/migrations/20130808084009_setup_pose_specs.rb +5 -0
- data/spec/{dummy/app → support}/models/posable_one.rb +1 -1
- data/spec/support/models/posable_three.rb +10 -0
- data/spec/{dummy/app → support}/models/posable_two.rb +1 -1
- data/spec/{dummy/app → support}/models/user.rb +1 -1
- data/spec/support/spec_manager.rb +105 -0
- metadata +70 -101
- data/app/models/pose/word.rb +0 -22
- data/db/migrate/20130308144915_pose_install.rb +0 -18
- data/lib/generators/pose/install/install_generator.rb +0 -56
- data/lib/generators/pose/install/templates/install_migration.rb +0 -24
- data/lib/generators/pose/remove/remove_generator.rb +0 -56
- data/lib/generators/pose/remove/templates/remove_migration.rb +0 -23
- data/lib/generators/pose/upgrade/templates/upgrade_migration.rb +0 -7
- data/lib/generators/pose/upgrade/upgrade_generator.rb +0 -35
- data/lib/pose/engine.rb +0 -5
- data/lib/pose/helpers.rb +0 -89
- data/lib/pose/railtie.rb +0 -19
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -30
- data/spec/dummy/config/environments/production.rb +0 -81
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -2
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/schema.rb +0 -47
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -309
- data/spec/dummy/log/test.log +0 -88518
- data/spec/dummy/script/rails +0 -6
- data/spec/lib/pose/helpers_spec.rb +0 -147
- data/spec/models/word_spec.rb +0 -42
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Pose
|
4
|
+
describe Word do
|
5
|
+
|
6
|
+
describe "::factory" do
|
7
|
+
|
8
|
+
context 'given a non-existing word' do
|
9
|
+
it 'creates the word in the database' do
|
10
|
+
expect(Word).to have(0).instances
|
11
|
+
Word.factory ['one']
|
12
|
+
expect(Word.pluck :text).to eql %w[ one ]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'existing word' do
|
17
|
+
before do
|
18
|
+
Word.create text: 'one'
|
19
|
+
@words = Word.factory ['one']
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns the word' do
|
23
|
+
expect(@words.map &:text).to eql %w[one]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not create a new Word in the database' do
|
27
|
+
expect(Word).to have(1).instance
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe 'class methods' do
|
34
|
+
|
35
|
+
shared_examples 'cleans unused words' do
|
36
|
+
it 'removes unused words' do
|
37
|
+
create :word
|
38
|
+
Word.remove_unused_words
|
39
|
+
expect(Word.count).to eql 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not remove used words' do
|
43
|
+
create :posable_one
|
44
|
+
Word.remove_unused_words
|
45
|
+
expect(Word.count).to be > 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a SQL database' do
|
50
|
+
before :each do
|
51
|
+
# TODO: do not mock class method
|
52
|
+
Pose.should_receive(:has_sql_connection?).and_return(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it_should_behave_like 'cleans unused words'
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'without a SQL database' do
|
59
|
+
before :each do
|
60
|
+
# TODO: do not mock class method
|
61
|
+
Pose.should_receive(:has_sql_connection?).and_return(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should_behave_like 'cleans unused words'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/pose_api_spec.rb
CHANGED
@@ -143,9 +143,9 @@ module Pose
|
|
143
143
|
describe "'limit' parameter" do
|
144
144
|
|
145
145
|
before :each do
|
146
|
-
@pos1 =
|
147
|
-
@pos2 =
|
148
|
-
@pos3 =
|
146
|
+
@pos1 = create :posable_one, text: 'foo', private: true
|
147
|
+
@pos2 = create :posable_one, text: 'foo', private: true
|
148
|
+
@pos3 = create :posable_one, text: 'foo', private: false
|
149
149
|
end
|
150
150
|
|
151
151
|
context 'with ids and no scope' do
|
@@ -193,7 +193,7 @@ module Pose
|
|
193
193
|
describe "'result_type' parameter" do
|
194
194
|
|
195
195
|
before :each do
|
196
|
-
@foo_one =
|
196
|
+
@foo_one = create :posable_one, text: 'foo one'
|
197
197
|
end
|
198
198
|
|
199
199
|
describe 'default behavior' do
|
@@ -215,9 +215,9 @@ module Pose
|
|
215
215
|
describe "'where' parameter" do
|
216
216
|
|
217
217
|
before :each do
|
218
|
-
@one =
|
219
|
-
@bar =
|
220
|
-
@two =
|
218
|
+
@one = create :posable_one, text: 'foo one', private: true
|
219
|
+
@bar = create :posable_one, text: 'bar one', private: true
|
220
|
+
@two = create :posable_one, text: 'foo two', private: false
|
221
221
|
end
|
222
222
|
|
223
223
|
context 'with result type :classes' do
|
@@ -241,7 +241,7 @@ module Pose
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'allows to combine several conditions' do
|
244
|
-
three =
|
244
|
+
three = create :posable_one, text: 'foo two', private: true
|
245
245
|
result = Pose.search 'foo',
|
246
246
|
PosableOne,
|
247
247
|
joins: PosableOne,
|
@@ -269,10 +269,10 @@ module Pose
|
|
269
269
|
describe ':joins parameter' do
|
270
270
|
|
271
271
|
before :each do
|
272
|
-
@user_1 =
|
273
|
-
@user_2 =
|
274
|
-
@one =
|
275
|
-
@two =
|
272
|
+
@user_1 = create :user, name: 'Jeff'
|
273
|
+
@user_2 = create :user, name: 'Jim'
|
274
|
+
@one = create :posable_one, text: 'snippet one', user: @user_1
|
275
|
+
@two = create :posable_one, text: 'snippet two', user: @user_2
|
276
276
|
end
|
277
277
|
|
278
278
|
it 'allows to use joined tables for queries' do
|
@@ -280,7 +280,7 @@ module Pose
|
|
280
280
|
PosableOne,
|
281
281
|
{ joins: [ PosableOne,
|
282
282
|
"INNER JOIN users on posable_ones.user_id=users.id" ],
|
283
|
-
where: ["users.name
|
283
|
+
where: ["users.name = 'Jeff'"] }
|
284
284
|
expect(result[PosableOne].map(&:text)).to eql ['snippet one']
|
285
285
|
end
|
286
286
|
|
@@ -320,5 +320,25 @@ module Pose
|
|
320
320
|
expect(result).to be_empty
|
321
321
|
end
|
322
322
|
end
|
323
|
+
|
324
|
+
describe "::has_sql_connection?" do
|
325
|
+
|
326
|
+
it 'recognizes mysql databases' do
|
327
|
+
ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::Mysql2Adapter'
|
328
|
+
expect(Pose.has_sql_connection?).to be_true
|
329
|
+
ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
|
330
|
+
expect(Pose.has_sql_connection?).to be_true
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'recognizes postgres databases' do
|
334
|
+
ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
|
335
|
+
expect(Pose.has_sql_connection?).to be_true
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'recognizes sqlite3 databases' do
|
339
|
+
ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
|
340
|
+
expect(Pose.has_sql_connection?).to be_true
|
341
|
+
end
|
342
|
+
end
|
323
343
|
end
|
324
344
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,42 +3,14 @@ if ENV['COVERALLS_CONFIG'] != 'nocoveralls'
|
|
3
3
|
Coveralls.wear!
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
ENV["RAILS_ENV"] ||= 'test'
|
8
|
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
9
|
-
require 'rspec/rails'
|
10
|
-
require 'rspec/autorun'
|
11
|
-
require 'factory_girl_rails'
|
6
|
+
require 'factory_girl'
|
12
7
|
require 'faker'
|
8
|
+
require 'pose'
|
13
9
|
|
14
|
-
#
|
15
|
-
# in spec/support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname __FILE__}/factories/**/*.rb"].each {|f| require f}
|
16
11
|
Dir["#{File.dirname __FILE__}/support/**/*.rb"].each {|f| require f}
|
17
12
|
|
18
13
|
RSpec.configure do |config|
|
19
|
-
# ## Mock Framework
|
20
|
-
#
|
21
|
-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
22
|
-
#
|
23
|
-
# config.mock_with :mocha
|
24
|
-
# config.mock_with :flexmock
|
25
|
-
# config.mock_with :rr
|
26
|
-
|
27
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
28
|
-
# examples within a transaction, remove the following line or assign false
|
29
|
-
# instead of true.
|
30
|
-
config.use_transactional_fixtures = true
|
31
|
-
|
32
|
-
# If true, the base class of anonymous controllers will be inferred
|
33
|
-
# automatically. This will be the default behavior in future versions of
|
34
|
-
# rspec-rails.
|
35
|
-
config.infer_base_class_for_anonymous_controllers = false
|
36
|
-
|
37
|
-
# Run specs in random order to surface order dependencies. If you find an
|
38
|
-
# order dependency and want to debug it, you can fix the order by providing
|
39
|
-
# the seed, which is printed after each run.
|
40
|
-
# --seed 1234
|
41
|
-
config.order = "random"
|
42
|
-
|
43
14
|
config.include FactoryGirl::Syntax::Methods
|
15
|
+
SpecManager.manage(config, ENV['POSE_ENV'])
|
44
16
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: sqlite3
|
3
|
+
database: spec/db/pose.sqlite3
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
|
7
|
+
mysql2:
|
8
|
+
adapter: mysql2
|
9
|
+
encoding: utf8
|
10
|
+
database: pose
|
11
|
+
min_messages: WARNING
|
12
|
+
|
13
|
+
mysql:
|
14
|
+
adapter: mysql
|
15
|
+
encoding: utf8
|
16
|
+
database: pose
|
17
|
+
min_messages: WARNING
|
18
|
+
|
19
|
+
postgres:
|
20
|
+
adapter: postgresql
|
21
|
+
encoding: utf8
|
22
|
+
database: pose
|
23
|
+
min_messages: WARNING
|
24
|
+
|
25
|
+
sqlite:
|
26
|
+
<<: *default
|
27
|
+
|
28
|
+
mysql2_ci:
|
29
|
+
adapter: mysql2
|
30
|
+
encoding: utf8
|
31
|
+
database: pose
|
32
|
+
username: travis
|
33
|
+
min_messages: WARNING
|
34
|
+
|
35
|
+
mysql_ci:
|
36
|
+
adapter: mysql
|
37
|
+
encoding: utf8
|
38
|
+
database: pose
|
39
|
+
username: travis
|
40
|
+
min_messages: WARNING
|
41
|
+
|
42
|
+
postgres_ci:
|
43
|
+
adapter: postgresql
|
44
|
+
encoding: utf8
|
45
|
+
database: pose
|
46
|
+
min_messages: WARNING
|
47
|
+
|
48
|
+
sqlite_ci:
|
49
|
+
adapter: sqlite3
|
50
|
+
database: ":memory:"
|
51
|
+
timeout: 500
|
@@ -0,0 +1,16 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: sqlite3
|
3
|
+
database: spec/db/pose.sqlite3
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
|
7
|
+
postgres:
|
8
|
+
adapter: postgresql
|
9
|
+
encoding: utf8
|
10
|
+
database: pose
|
11
|
+
username: pose
|
12
|
+
password: pose
|
13
|
+
min_messages: WARNING
|
14
|
+
|
15
|
+
sqlite:
|
16
|
+
<<: *default
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'database_cleaner'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
|
5
|
+
class SpecManager
|
6
|
+
attr_reader :env
|
7
|
+
|
8
|
+
# @param [String, Symbol] env
|
9
|
+
def initialize(env = 'default')
|
10
|
+
@env = env.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [Rspec::Config] config
|
14
|
+
# @param [String, Symbol] env
|
15
|
+
def self.manage(config, env)
|
16
|
+
env ||= 'default'
|
17
|
+
|
18
|
+
config.order = "random"
|
19
|
+
|
20
|
+
config.include FactoryGirl::Syntax::Methods
|
21
|
+
|
22
|
+
config.before(:each) do
|
23
|
+
DatabaseCleaner.start
|
24
|
+
end
|
25
|
+
|
26
|
+
config.after(:each) do
|
27
|
+
DatabaseCleaner.clean
|
28
|
+
end
|
29
|
+
|
30
|
+
spec_manager = self.new(env)
|
31
|
+
|
32
|
+
config.before(:suite) do
|
33
|
+
spec_manager.init!
|
34
|
+
end
|
35
|
+
|
36
|
+
config.after(:suite) do
|
37
|
+
spec_manager.drop_database
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String]
|
42
|
+
def db_adapter
|
43
|
+
database_config['adapter']
|
44
|
+
end
|
45
|
+
|
46
|
+
def init!
|
47
|
+
database_config or raise 'Wrong database configuration, please specify spec/support/config/database.yml'
|
48
|
+
puts "Running specs with #{db_adapter}."
|
49
|
+
create_database
|
50
|
+
establish_db_connection
|
51
|
+
migrate_database
|
52
|
+
apply_cleaner_strategy
|
53
|
+
end
|
54
|
+
|
55
|
+
def db_connection
|
56
|
+
ActiveRecord::Base.connection
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_database
|
60
|
+
establish_service_connection
|
61
|
+
db_connection.create_database(database_config['database']) if db_connection.respond_to?(:create_database)
|
62
|
+
end
|
63
|
+
|
64
|
+
def drop_database
|
65
|
+
establish_service_connection
|
66
|
+
db_connection.drop_database(database_config['database']) if db_connection.respond_to?(:drop_database)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Hash]
|
70
|
+
def database_config
|
71
|
+
@database_config ||= YAML.load_file('spec/support/config/database.yml')[env]
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def apply_cleaner_strategy
|
78
|
+
case db_adapter
|
79
|
+
when 'postgresql', 'mysql', 'mysql2'
|
80
|
+
DatabaseCleaner.strategy = :transaction
|
81
|
+
DatabaseCleaner.clean_with(:truncation)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def establish_db_connection
|
86
|
+
ActiveRecord::Base.establish_connection(database_config)
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param [Integer, nil] version
|
90
|
+
def migrate_database version = nil
|
91
|
+
ActiveRecord::Migrator.migrate "spec/support/migrations", version.try(:to_i)
|
92
|
+
end
|
93
|
+
|
94
|
+
def establish_service_connection
|
95
|
+
case db_adapter
|
96
|
+
when 'mysql', 'mysql2'
|
97
|
+
ActiveRecord::Base.establish_connection(database_config.merge('database' => nil))
|
98
|
+
when 'postgresql'
|
99
|
+
ActiveRecord::Base.establish_connection(database_config.merge('database' => 'postgres',
|
100
|
+
'schema_search_path' => 'public'))
|
101
|
+
when 'sqlite3'
|
102
|
+
ActiveRecord::Base.establish_connection(database_config)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|