activerecord-deprecated_finders 0.0.3 → 1.0.0

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.
data/.gitignore CHANGED
@@ -3,7 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
6
+ *.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
@@ -1,8 +1,16 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - gemfiles/Gemfile-edge
7
+ - Gemfile
4
8
  notifications:
5
- email:
6
- - j@jonathanleighton.com
9
+ email: false
10
+ campfire:
11
+ on_success: change
12
+ on_failure: always
13
+ rooms:
14
+ - secure: "DwWWfmRXWSYoelIo3W6H99FrLM2V9ugFoAu+xBo42n2pNV44lU+8T9O+zWkV\nwD3Lz+7URB/5IRPcEel/KYaRYNJl71YUBgtlcvjM7Xl/7YGLYFAcPT2RXfKA\nctvckk/5NehmSawnLhhvMz2gKtIx/fIwCVqxUnRqqYE0eEQaONA="
7
15
  before_install:
8
16
  - gem install bundler
data/Gemfile CHANGED
@@ -1,10 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in active_record_deprecated_finders.gemspec
4
3
  gemspec
5
4
 
6
- if ENV['RAILS']
7
- gem 'rails', path: ENV['RAILS']
8
- else
9
- gem 'rails', git: 'git://github.com/rails/rails', branch: 'master'
10
- end
5
+ gem 'rails', '>= 4.0.0.beta', '< 5'
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ deps = `git ls-files`.split("\n") - [specname]
16
16
  task :gemspec => specname
17
17
 
18
18
  file specname => deps do
19
- files = `git ls-files`.split("\n")
19
+ files = `git ls-files`.split("\n") - Dir["gemfiles/*"]
20
20
  test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
 
@@ -4,7 +4,7 @@ require File.expand_path('../lib/active_record/deprecated_finders/version', __FI
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Jon Leighton"]
6
6
  gem.email = ["j@jonathanleighton.com"]
7
- gem.description = %q{This gem contains deprecated finder APIs extracted from Active Record.}
7
+ gem.description = %q{Deprecated finder APIs extracted from Active Record.}
8
8
  gem.summary = %q{This gem contains deprecated finder APIs extracted from Active Record.}
9
9
  gem.homepage = "https://github.com/rails/activerecord-deprecated_finders"
10
10
 
@@ -4,7 +4,7 @@ require File.expand_path('../lib/active_record/deprecated_finders/version', __FI
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Jon Leighton"]
6
6
  gem.email = ["j@jonathanleighton.com"]
7
- gem.description = %q{This gem contains deprecated finder APIs extracted from Active Record.}
7
+ gem.description = %q{Deprecated finder APIs extracted from Active Record.}
8
8
  gem.summary = %q{This gem contains deprecated finder APIs extracted from Active Record.}
9
9
  gem.homepage = "https://github.com/rails/activerecord-deprecated_finders"
10
10
 
@@ -38,10 +38,16 @@ module ActiveRecord::Associations::Builder
38
38
  self.valid_options += [:select, :conditions, :include, :readonly]
39
39
 
40
40
  def initialize_with_deprecated_options(model, name, scope, options)
41
- if scope.is_a?(Hash)
42
- options = scope
43
- deprecated_options = options.slice(*DEPRECATED_OPTIONS)
41
+ options = scope if scope.is_a?(Hash)
42
+ deprecated_options = options.slice(*DEPRECATED_OPTIONS)
43
+
44
+ if scope.respond_to?(:call) && !deprecated_options.empty?
45
+ raise ArgumentError,
46
+ "Invalid mix of scope block and deprecated finder options on " \
47
+ "ActiveRecord association: #{model.name}.#{macro} :#{name}"
48
+ end
44
49
 
50
+ if scope.is_a?(Hash)
45
51
  if deprecated_options.empty?
46
52
  scope = nil
47
53
  else
@@ -4,8 +4,12 @@ module ActiveRecord
4
4
  module InterceptDynamicInstantiators
5
5
  def method_missing(method, *args, &block)
6
6
  match = DynamicMatchers::Method.match(klass, method)
7
+ sanitized_method = match.class.prefix + match.class.suffix if match
7
8
 
8
- if match && match.is_a?(DynamicMatchers::Instantiator)
9
+ if match && self.respond_to?(sanitized_method)
10
+ self.send(sanitized_method, Hash[match.attribute_names.zip(args)])
11
+
12
+ elsif match && match.is_a?(DynamicMatchers::Instantiator)
9
13
  scoping do
10
14
  klass.send(method, *args) do |record|
11
15
  proxy_association.add_to_target(record)
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module DeprecatedFinders
3
- VERSION = "0.0.3"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -7,6 +7,14 @@ describe 'associations' do
7
7
  @klass.table_name = 'posts'
8
8
  end
9
9
 
10
+ it 'find_or_create_by on has_many through should work' do
11
+ physician = Physician.create!
12
+ ActiveSupport::Deprecation.silence do
13
+ physician.patients.find_or_create_by_name('Tim')
14
+ end
15
+ assert_equal 1, Appointment.count
16
+ end
17
+
10
18
  it 'translates hash scope options into scopes' do
11
19
  assert_deprecated do
12
20
  @klass.has_many :comments, readonly: 'a', order: 'b', limit: 'c', group: 'd', having: 'e',
@@ -49,4 +57,10 @@ describe 'associations' do
49
57
  scope = @klass.new.comments
50
58
  scope.limit_value.must_equal 5
51
59
  end
60
+
61
+ it "raises an ArgumentError when declaration uses both scope and deprecated options" do
62
+ assert_raises(ArgumentError) do
63
+ @klass.has_many :comments, -> { limit 5 }, :order=>'b'
64
+ end
65
+ end
52
66
  end
@@ -44,8 +44,8 @@ describe 'apply_finder_options' do
44
44
  end
45
45
 
46
46
  it 'supports :order' do
47
- scope = Post.scoped.apply_finder_options(:order => :foo)
48
- scope.order_values.must_equal [:foo]
47
+ scope = Post.scoped.apply_finder_options(:order => 'foo')
48
+ scope.order_values.must_equal ['foo']
49
49
  end
50
50
 
51
51
  it 'supports :select' do
@@ -17,6 +17,19 @@ ActiveRecord::Schema.define do
17
17
  t.string :title
18
18
  t.references :post
19
19
  end
20
+
21
+ create_table :appointments do |t|
22
+ t.integer :physician_id
23
+ t.integer :patient_id
24
+ end
25
+
26
+ create_table :physicians do |t|
27
+ t.string :name
28
+ end
29
+
30
+ create_table :patients do |t|
31
+ t.string :name
32
+ end
20
33
  end
21
34
 
22
35
  class Post < ActiveRecord::Base
@@ -29,6 +42,19 @@ class Comment < ActiveRecord::Base
29
42
  end
30
43
  end
31
44
 
45
+ class Appointment < ActiveRecord::Base
46
+ belongs_to :physician
47
+ belongs_to :patient
48
+ end
49
+
50
+ class Patient < ActiveRecord::Base
51
+ end
52
+
53
+ class Physician < ActiveRecord::Base
54
+ has_many :appointments
55
+ has_many :patients, through: :appointments
56
+ end
57
+
32
58
  require 'active_support/testing/deprecation'
33
59
  ActiveSupport::Deprecation.debug = true
34
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-deprecated_finders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
12
+ date: 2013-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -65,7 +65,7 @@ dependencies:
65
65
  - - ~>
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.3'
68
- description: This gem contains deprecated finder APIs extracted from Active Record.
68
+ description: Deprecated finder APIs extracted from Active Record.
69
69
  email:
70
70
  - j@jonathanleighton.com
71
71
  executables: []
@@ -136,3 +136,4 @@ test_files:
136
136
  - test/scoped_test.rb
137
137
  - test/update_all_test.rb
138
138
  - test/with_scope_test.rb
139
+ has_rdoc: