legacy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ Rake::TestTask.new(:test) do |t|
31
31
  t.libs << 'lib'
32
32
  t.libs << 'test'
33
33
  t.pattern = 'test/**/*_test.rb'
34
- t.verbose = false
34
+ t.verbose = true
35
35
  end
36
36
 
37
37
  task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{legacy}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roy van der Meij"]
@@ -1,14 +1,21 @@
1
1
  module Legacy
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ def self.real_method(columns, method)
7
+ columns.inject(method.to_s){|m, c| m.gsub(c.downcase, c)}.to_sym
8
+ end
9
+
2
10
  def method_missing(method_id, *args, &block)
3
- super(select_real_method_id(method_id), *args, &block)
11
+ super(Legacy.real_method(attributes.keys, method_id), *args, &block)
4
12
  end
5
13
 
6
- def select_real_method_id(method_id)
7
- real_method_id = attributes.keys.detect{ |c| c.to_s.downcase == method_id.to_s.downcase.gsub(/=/, '') }
8
- return method_id unless real_method_id
14
+ module ClassMethods
15
+ def method_missing(method_id, *args, &block)
16
+ method_id = Legacy.real_method(column_names, method_id) if method_id.to_s =~ /^find(.*)by(.*?)/
9
17
 
10
- method_id = method_id.to_s
11
- method_id[0..(real_method_id.length - 1)] = real_method_id
12
- method_id
18
+ super(method_id, *args, &block)
19
+ end
13
20
  end
14
21
  end
@@ -14,4 +14,15 @@ class LegacyTest < ActiveSupport::TestCase
14
14
  assert_equal "Testing title", post.title
15
15
  assert_equal "Testing description", post.description
16
16
  end
17
+
18
+ test "should find post by find_by_title_and_description" do
19
+ post = Post.new
20
+ post.title = "find_title"
21
+ post.description = "find_description"
22
+ post.save
23
+
24
+ find_post = Post.find_by_title_and_description("find_title", "find_description")
25
+ assert_equal "find_title", find_post.title
26
+ assert_equal "find_description", find_post.description
27
+ end
17
28
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legacy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roy van der Meij