mongoid_sortable_relation 0.0.4 → 0.0.5

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: 18c2ac753124c62fa2ff6b76ec45b500d43e4613
4
- data.tar.gz: 08663bcb6f55cf276221a9cae1aefeb1b29ecaee
3
+ metadata.gz: 477483627f1e0806bcc9d9f901613d897a69f696
4
+ data.tar.gz: 7de40f9ebdd7efa69728f654755304f58dd6dfd5
5
5
  SHA512:
6
- metadata.gz: 78718f076ff1cb39dde042cc25d58ed24515f5f000ae3f22a615376cb174504521d7da6808bb59254b05087475ff8393ba7ebd7665701a12ad458bc940c50ed1
7
- data.tar.gz: f9eebc73e6bc337ed237c81947917563eb2cda7d7eef5f9372e573a08934b52932df7fc393b0751a66cfd5b29ae682d2bfc3634c04adb91917eb2f44dbb99931
6
+ metadata.gz: 26da733006630ea67858857fe54468ef0291740467ba8b6a9dd239d30579a0c24c38739c300e4659699870d0f0a2bbdbc63afb81f7c628a9beab23f0b32dc304
7
+ data.tar.gz: e42439a89a2194843da7254e72c2b809be5901664283df54680f33a7d298804ed1990626c3c6a083de50522b9670622f44b91f7d5b2daf24f5927039628f878f
@@ -1,4 +1,3 @@
1
- require 'rails'
2
1
  require 'mongoid'
3
2
  require 'mongoid_criteria_filter'
4
3
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MongoidSortableRelation
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
@@ -0,0 +1,9 @@
1
+ class Post
2
+ include Mongoid::Document
3
+
4
+ belongs_to :user
5
+ has_and_belongs_to_many :tags, :sortable => true
6
+
7
+ field :title, :type => String
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ class Tag
2
+ include Mongoid::Document
3
+
4
+ has_and_belongs_to_many :posts
5
+
6
+ field :name, :type => String
7
+
8
+ end
@@ -0,0 +1,9 @@
1
+ class User
2
+ include Mongoid::Document
3
+
4
+ has_many :posts, :sortable => true
5
+
6
+ field :name, :type => String
7
+ field :age, :type => Integer
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :post do
4
+ title 'Title'
5
+ end
6
+
7
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ FactoryGirl.define do
3
+
4
+ factory :tag do
5
+ name 'Name'
6
+ end
7
+
8
+ 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,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Many to many sortable relation' do
4
+
5
+ let(:post) do
6
+ FactoryGirl.create :post
7
+ end
8
+
9
+ describe 'get relations' do
10
+
11
+ let!(:tags) do
12
+ tag1 = FactoryGirl.create :tag, :name => 'Name1'
13
+ tag2 = FactoryGirl.create :tag, :name => 'Name2'
14
+ tag3 = FactoryGirl.create :tag, :name => 'Name3'
15
+ post.tags = [tag2, tag1, tag3]
16
+ post.save
17
+ end
18
+
19
+ it 'returns ordered relations' do
20
+ expect(post.tags.map(&:name)).to eq(%w(Name2 Name1 Name3))
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::Relations::Metadata do
4
+
5
+ let(:post_relation) do
6
+ User.relations['posts']
7
+ end
8
+
9
+ it 'is sortable' do
10
+ expect(post_relation.sortable?).to be
11
+ end
12
+
13
+ it 'generates sortable field name' do
14
+ expect(post_relation.sortable_field).to eq(:'user_position')
15
+ end
16
+
17
+ it 'generates sortable scope name' do
18
+ expect(post_relation.sortable_scope).to eq(:'sort_for_user')
19
+ end
20
+
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'One to many sortable relation' do
4
+
5
+ let(:user) do
6
+ FactoryGirl.create :user
7
+ end
8
+
9
+ describe 'get relations' do
10
+
11
+ let!(:posts) do
12
+ FactoryGirl.create :post, :user => user, :title => 'Title1', :user_position => 2
13
+ FactoryGirl.create :post, :user => user, :title => 'Title2', :user_position => 1
14
+ FactoryGirl.create :post, :user => user, :title => 'Title3', :user_position => 3
15
+ end
16
+
17
+ it 'returns ordered relations' do
18
+ expect(user.posts.map(&:title)).to eq(%w(Title2 Title1 Title3))
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Origin::Optional do
4
+
5
+ describe '#prepend_order_by' do
6
+
7
+ let!(:users) do
8
+ FactoryGirl.create :user, :name => 'Name1', :age => 2
9
+ FactoryGirl.create :user, :name => 'Name2', :age => 1
10
+ FactoryGirl.create :user, :name => 'Name3', :age => 2
11
+ end
12
+
13
+ it 'adds order' do
14
+ ordered_users = User.prepend_order_by(:name => :desc)
15
+ expect(ordered_users.map(&:name)).to eq(%w(Name3 Name2 Name1))
16
+ end
17
+
18
+ it 'prepends order' do
19
+ ordered_users = User.order_by(:name => :desc).prepend_order_by(:age => :asc)
20
+ expect(ordered_users.map(&:name)).to eq(%w(Name2 Name3 Name1))
21
+ end
22
+
23
+ end
24
+
25
+ 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_sortable_relation'
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_sortable_relation_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,55 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_sortable_relation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-19 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
  - !ruby/object:Gem::Dependency
42
28
  name: mongoid_criteria_filter
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  description: It adds possibility for sorting relation
@@ -69,6 +55,17 @@ files:
69
55
  - lib/mongoid_sortable_relation/many_to_many/referenced.rb
70
56
  - lib/mongoid_sortable_relation/metadata.rb
71
57
  - lib/mongoid_sortable_relation/version.rb
58
+ - spec/app/models/post.rb
59
+ - spec/app/models/tag.rb
60
+ - spec/app/models/user.rb
61
+ - spec/factories/post.rb
62
+ - spec/factories/tag.rb
63
+ - spec/factories/user.rb
64
+ - spec/models/many_to_many_spec.rb
65
+ - spec/models/metadata_spec.rb
66
+ - spec/models/one_to_many_spec.rb
67
+ - spec/models/origin_optional_spec.rb
68
+ - spec/spec_helper.rb
72
69
  homepage: https://github.com/Rademade/mongoid_sortable_relation
73
70
  licenses:
74
71
  - MIT
@@ -79,12 +76,12 @@ require_paths:
79
76
  - lib
80
77
  required_ruby_version: !ruby/object:Gem::Requirement
81
78
  requirements:
82
- - - '>='
79
+ - - ">="
83
80
  - !ruby/object:Gem::Version
84
81
  version: '0'
85
82
  required_rubygems_version: !ruby/object:Gem::Requirement
86
83
  requirements:
87
- - - '>='
84
+ - - ">="
88
85
  - !ruby/object:Gem::Version
89
86
  version: '0'
90
87
  requirements: []
@@ -93,4 +90,15 @@ rubygems_version: 2.2.2
93
90
  signing_key:
94
91
  specification_version: 4
95
92
  summary: Extension for mongoid.
96
- test_files: []
93
+ test_files:
94
+ - spec/models/origin_optional_spec.rb
95
+ - spec/models/metadata_spec.rb
96
+ - spec/models/many_to_many_spec.rb
97
+ - spec/models/one_to_many_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/factories/post.rb
100
+ - spec/factories/user.rb
101
+ - spec/factories/tag.rb
102
+ - spec/app/models/post.rb
103
+ - spec/app/models/user.rb
104
+ - spec/app/models/tag.rb