mongoid_criteria_filter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b93d69eaf85c06a005218e84706157870302fb57
4
- data.tar.gz: 5dbf65c1e13a94e6af56ec154737e67fcc98b0fc
3
+ metadata.gz: 6b9d909c8cc493adbde6ef0884ba448b31176f68
4
+ data.tar.gz: d293a24bc672de73e7a8a9c0c5b552329caea4f6
5
5
  SHA512:
6
- metadata.gz: e69c129859f22007452b9857cb739977882e97b4a207cbade4c1a62ad0600b7719fb0bcfd4695966bdc2b5851da56a42f3d74f6de5b142e0e1a5c01d72ed87ca
7
- data.tar.gz: b5eab98965fbd20146ea36e3ed7f403230259513d50c713d9310cb005318bacf0f2af7b98bd689ff18a9a6e492a13c402cd97d2583b450a5807e843e048448bf
6
+ metadata.gz: 825579e605d17dd27c33b64c88db995eccdaaff65b1141abbbb98d14019eee6b72603f454bb676de0f5d35bb8c3ef0ccabda24f421aaefe845294f7fc0ed25ce
7
+ data.tar.gz: 74f6ca5093496ec78f00e5ba3b7407e51a1b23c55beb95a7ed92433e1b243b77744a2fc18dcf2d9248ea9fabc334eb72ca31c067ef6837a1ded292e111cdffe5
@@ -1,4 +1,3 @@
1
- require 'rails'
2
1
  require 'mongoid'
3
2
 
4
3
  require 'mongoid_criteria_filter/criteria'
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MongoidCriteriaFilter
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -0,0 +1,6 @@
1
+ class User
2
+ include Mongoid::Document
3
+
4
+ field :name, :type => String
5
+
6
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ FactoryGirl.define do
3
+
4
+ factory :user do
5
+ name 'John'
6
+ end
7
+
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::Criteria do
4
+
5
+ describe '#add_filter' do
6
+
7
+ let!(:users) do
8
+ FactoryGirl.create :user, :name => 'Name1'
9
+ FactoryGirl.create :user, :name => 'Name2'
10
+ FactoryGirl.create :user, :name => 'Name3'
11
+ end
12
+
13
+ context 'without additional order' do
14
+
15
+ it 'applies callback' do
16
+ names_order = %w(Name3 Name1 Name2)
17
+ criteria = User.all.add_filter do |users|
18
+ users = users.to_a
19
+ names_order.map do |name|
20
+ users.select { |user| user.name == name }.first
21
+ end
22
+ end
23
+ expect(criteria.to_a.map(&:name)).to eq(names_order)
24
+ end
25
+
26
+ end
27
+
28
+ context 'with additional order' do
29
+
30
+ it 'does not apply callback' do
31
+ names_order = %w(Name3 Name1 Name2)
32
+ criteria = User.order_by(:name => :desc).add_filter do |users|
33
+ users = users.to_a
34
+ names_order.map do |name|
35
+ users.select { |user| user.name == name }.first
36
+ end
37
+ end
38
+ expect(criteria.to_a.map(&:name)).to eq(%w(Name3 Name2 Name1))
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,68 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ MODELS = File.join(File.dirname(__FILE__), 'app/models')
5
+ $LOAD_PATH.unshift(MODELS)
6
+
7
+ require 'mongoid_criteria_filter'
8
+ require 'action_controller'
9
+ require 'rspec'
10
+ require 'database_cleaner'
11
+ require 'factory_girl_rails'
12
+
13
+ ENV['MONGOID_SPEC_HOST'] ||= 'localhost'
14
+ ENV['MONGOID_SPEC_PORT'] ||= '27017'
15
+
16
+ HOST = ENV['MONGOID_SPEC_HOST']
17
+ PORT = ENV['MONGOID_SPEC_PORT'].to_i
18
+
19
+ CONFIG = {
20
+ :sessions => {
21
+ :default => {
22
+ :database => 'mongoid_criteria_filter_test',
23
+ :hosts => ["#{HOST}:#{PORT}"]
24
+ }
25
+ }
26
+ }
27
+
28
+ FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
29
+ FactoryGirl.reload
30
+
31
+ Mongoid.configure do |config|
32
+ config.load_configuration(CONFIG)
33
+ end
34
+
35
+ Dir[File.join(MODELS, '*.rb')].sort.each do |file|
36
+ name = File.basename(file, '.rb')
37
+ autoload name.camelize.to_sym, name
38
+ end
39
+
40
+ module Rails
41
+ class Application
42
+ end
43
+ end
44
+
45
+ module MyApp
46
+ class Application < Rails::Application
47
+ end
48
+ end
49
+
50
+ RSpec.configure do |config|
51
+
52
+ config.order = 'random'
53
+ config.formatter = :documentation
54
+
55
+ config.before :suite do
56
+ DatabaseCleaner.strategy = :truncation
57
+ DatabaseCleaner.orm = 'mongoid'
58
+ end
59
+
60
+ config.before :each do
61
+ DatabaseCleaner.start
62
+ end
63
+
64
+ config.after :each do
65
+ DatabaseCleaner.clean
66
+ end
67
+
68
+ end
metadata CHANGED
@@ -1,41 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_criteria_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Melanitskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '4.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '4.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: mongoid
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - '>='
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '0'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - '>='
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  description: It adds possibility for criteria callbacks (data filters)
@@ -49,6 +35,10 @@ files:
49
35
  - lib/mongoid_criteria_filter/criteria.rb
50
36
  - lib/mongoid_criteria_filter/origin_optional.rb
51
37
  - lib/mongoid_criteria_filter/version.rb
38
+ - spec/app/models/user.rb
39
+ - spec/factories/user.rb
40
+ - spec/models/criteria_spec.rb
41
+ - spec/spec_helper.rb
52
42
  homepage: https://github.com/Rademade/mongoid_criteria_filter
53
43
  licenses:
54
44
  - MIT
@@ -59,12 +49,12 @@ require_paths:
59
49
  - lib
60
50
  required_ruby_version: !ruby/object:Gem::Requirement
61
51
  requirements:
62
- - - '>='
52
+ - - ">="
63
53
  - !ruby/object:Gem::Version
64
54
  version: '0'
65
55
  required_rubygems_version: !ruby/object:Gem::Requirement
66
56
  requirements:
67
- - - '>='
57
+ - - ">="
68
58
  - !ruby/object:Gem::Version
69
59
  version: '0'
70
60
  requirements: []
@@ -73,4 +63,8 @@ rubygems_version: 2.2.2
73
63
  signing_key:
74
64
  specification_version: 4
75
65
  summary: Extension for mongoid.
76
- test_files: []
66
+ test_files:
67
+ - spec/models/criteria_spec.rb
68
+ - spec/spec_helper.rb
69
+ - spec/factories/user.rb
70
+ - spec/app/models/user.rb