scopes_for_associations 0.1.4 → 0.1.5

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.
@@ -0,0 +1,72 @@
1
+ # Scopes for Associations [![Build Status](https://secure.travis-ci.org/ordinaryzelig/scopes_for_associations.png?branch=master)](http://travis-ci.org/ordinaryzelig/scopes_for_associations)
2
+
3
+ https://github.com/ordinaryzelig/scopes_for_associations
4
+
5
+ ## Description
6
+
7
+ Define very basic, commonly used scopes for ActiveRecord associations.
8
+
9
+ ## Description through code
10
+
11
+ ```ruby
12
+ class Movie < ActiveRecord::Base
13
+ belongs_to :director
14
+ scopes_for_associations
15
+ end
16
+
17
+ Movie.for_director_id(Director.first.id)
18
+ #=> [#<Movie ..., director_id: 1>]
19
+ Movie.for_director(Director.first)
20
+ #=> [#<Movie ..., director_id: 1>]
21
+ Movie.for(Director.first)
22
+ #=> [#<Movie ..., director_id: 1>]
23
+ ```
24
+
25
+ ## Supported association types
26
+
27
+ * belongs_to (non-polymorpic and polymorphic)
28
+
29
+ If you're like me and prefer learning through looking at code,
30
+ read through the specs.
31
+ The examples here are basically reproductions of the tests.
32
+
33
+ ### belongs_to (non-polymorphic)
34
+
35
+ ```ruby
36
+ class Movie < ActiveRecord::Base
37
+ belongs_to :director
38
+ scopes_for_associations
39
+ end
40
+
41
+ Movie.for_director_id(Director.first.id)
42
+ #=> [#<Movie ..., director_id: 1>]
43
+ Movie.for_director(Director.first)
44
+ #=> [#<Movie ..., director_id: 1>]
45
+ Movie.for(Director.first)
46
+ #=> [#<Movie ..., director_id: 1>]
47
+ ```
48
+
49
+ ### belongs_to (polymorphic)
50
+
51
+ ```ruby
52
+ class Movie < ActiveRecord::base
53
+ # It is important to define this association.
54
+ has_many :comments, :as => :commentable
55
+ end
56
+ class Comment < ActiveRecord::Base
57
+ belongs_to :commentable, :polymorphic => true
58
+ end
59
+
60
+ Comment.for_commentable_id(Movie.first.id)
61
+ #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>]
62
+ Comment.for_commentable_type('Movie')
63
+ #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>, ...]
64
+ Comment.for_commentable(movie)
65
+ #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>]
66
+ Comment.for(Movie.first)
67
+ #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>]
68
+ ```
69
+
70
+ ## Compatibility
71
+
72
+ Tested with ActiveRecord >=3.0.0
@@ -1,3 +1,3 @@
1
1
  module ScopesForAssociations
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split($/).map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.add_dependency 'activerecord', '>= 3.0.0'
22
+ s.add_runtime_dependency 'activerecord', '>= 3.0.0'
23
+ s.add_runtime_dependency 'rake', ['>= 0.8.7']
23
24
 
24
25
  s.add_development_dependency 'awesome_print'
25
26
  s.add_development_dependency 'rspec', '2.5.0'
@@ -68,8 +68,10 @@ describe ScopesForAssociations do
68
68
  end
69
69
 
70
70
  it 'should scope for association as object' do
71
- Comment.for_commentable(movie).should query_the_same_as(Comment.where(:commentable_type => 'Movie', :commentable_id => movie.id))
72
- Comment.for_commentable(trailer).should query_the_same_as(Comment.where(:commentable_type => 'Trailer', :commentable_id => trailer.id))
71
+ # The order of the expected where statements is necessary for some reason.
72
+ # This came up when I used bundle exec rake, but did not fail when I used rake alone. Go figure.
73
+ Comment.for_commentable(movie).should query_the_same_as(Comment.where(:commentable_type => 'Movie').where(:commentable_id => movie.id))
74
+ Comment.for_commentable(trailer).should query_the_same_as(Comment.where(:commentable_type => 'Trailer').where(:commentable_id => trailer.id))
73
75
  end
74
76
 
75
77
  it 'should have an all encompassing scope :for' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scopes_for_associations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jared Ning
@@ -35,9 +35,25 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: awesome_print
38
+ name: rake
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 49
46
+ segments:
47
+ - 0
48
+ - 8
49
+ - 7
50
+ version: 0.8.7
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: awesome_print
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
59
  - - ">="
@@ -47,11 +63,11 @@ dependencies:
47
63
  - 0
48
64
  version: "0"
49
65
  type: :development
50
- version_requirements: *id002
66
+ version_requirements: *id003
51
67
  - !ruby/object:Gem::Dependency
52
68
  name: rspec
53
69
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
55
71
  none: false
56
72
  requirements:
57
73
  - - "="
@@ -63,11 +79,11 @@ dependencies:
63
79
  - 0
64
80
  version: 2.5.0
65
81
  type: :development
66
- version_requirements: *id003
82
+ version_requirements: *id004
67
83
  - !ruby/object:Gem::Dependency
68
84
  name: sqlite3
69
85
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
86
+ requirement: &id005 !ruby/object:Gem::Requirement
71
87
  none: false
72
88
  requirements:
73
89
  - - "="
@@ -79,7 +95,7 @@ dependencies:
79
95
  - 5
80
96
  version: 1.3.5
81
97
  type: :development
82
- version_requirements: *id004
98
+ version_requirements: *id005
83
99
  description: Define very basic, commonly used scopes for ActiveRecord associations. E.g. if a Post model has an author and a category association, scopes will be defined like Post.for(author) or Post.for(category).
84
100
  email:
85
101
  - jared@redningja.com
@@ -95,7 +111,7 @@ files:
95
111
  - .rvmrc
96
112
  - .travis.yml
97
113
  - Gemfile
98
- - README.rdoc
114
+ - README.md
99
115
  - Rakefile
100
116
  - gemfiles/active_record-3.0.Gemfile
101
117
  - gemfiles/active_record-3.1.Gemfile
@@ -1,70 +0,0 @@
1
- = Scopes for Associations [![Build Status](https://secure.travis-ci.org/ordinaryzelig/fandango.png?branch=master)](http://travis-ci.org/ordinaryzelig/fandango)
2
-
3
- https://github.com/ordinaryzelig/scopes_for_associations
4
-
5
- == Description
6
-
7
- Define very basic, commonly used scopes for ActiveRecord associations.
8
-
9
- == Description through code
10
-
11
- class Movie < ActiveRecord::Base
12
- belongs_to :director
13
- scopes_for_associations
14
- end
15
-
16
- Movie.for_director_id(Director.first.id)
17
- #=> [#<Movie ..., director_id: 1>]
18
- Movie.for_director(Director.first)
19
- #=> [#<Movie ..., director_id: 1>]
20
- Movie.for(Director.first)
21
- #=> [#<Movie ..., director_id: 1>]
22
-
23
- == Supported association types
24
-
25
- * belongs_to (non-polymorpic and polymorphic)
26
-
27
- If you're like me and prefer learning through looking at code,
28
- read through the specs.
29
- The examples here are basically reproductions of the tests.
30
-
31
- === belongs_to (non-polymorphic)
32
-
33
- class Movie < ActiveRecord::Base
34
- belongs_to :director
35
- scopes_for_associations
36
- end
37
-
38
- Movie.for_director_id(Director.first.id)
39
- #=> [#<Movie ..., director_id: 1>]
40
- Movie.for_director(Director.first)
41
- #=> [#<Movie ..., director_id: 1>]
42
- Movie.for(Director.first)
43
- #=> [#<Movie ..., director_id: 1>]
44
-
45
- === belongs_to (polymorphic)
46
-
47
- class Movie < ActiveRecord::base
48
- # It is important to define this association.
49
- has_many :comments, :as => :commentable
50
- end
51
- class Comment < ActiveRecord::Base
52
- belongs_to :commentable, :polymorphic => true
53
- end
54
-
55
- Comment.for_commentable_id(Movie.first.id)
56
- #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>]
57
- Comment.for_commentable_type('Movie')
58
- #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>, ...]
59
- Comment.for_commentable(movie)
60
- #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>]
61
- Comment.for(Movie.first)
62
- #=> [#<Comment ..., commentable_type: "Movie", commentable_id: 1>]
63
-
64
- == Installation
65
-
66
- gem install scopes_for_associations
67
-
68
- == Compatibility
69
-
70
- works with ActiveRecord >=3.0.0