difference 1.0.1 → 1.0.2.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +1 -1
- data/README.rdoc +15 -8
- data/difference.gemspec +4 -1
- data/lib/difference/version.rb +1 -1
- data/lib/difference.rb +0 -2
- data/test/setup/db/.gitkeep +1 -0
- data/test/test_difference.rb +31 -0
- data/test/test_helper.rb +19 -0
- metadata +60 -12
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
|
2
|
-
Difference is used to find difference between
|
2
|
+
Difference is used to find difference between 2 objects of same class.
|
3
3
|
|
4
|
+
{<img src="https://badge.fury.io/rb/difference.png" alt="Gem Version" />}[http://badge.fury.io/rb/difference]
|
5
|
+
{<img src="https://travis-ci.org/gouravtiwari/difference.png?branch=master" alt="Build Status" />}[https://travis-ci.org/gouravtiwari/difference]
|
6
|
+
|
7
|
+
Supported versions Ruby 1.9.3+
|
4
8
|
|
5
9
|
Usage
|
6
10
|
1. Paste this line in your Gemfile
|
@@ -15,22 +19,25 @@ Eg.
|
|
15
19
|
a=Foo.find 1
|
16
20
|
b=Foo.find 3
|
17
21
|
|
18
|
-
|
22
|
+
Now you can use,
|
19
23
|
a.differs_from b
|
20
24
|
|
21
|
-
|
25
|
+
will return a hash:
|
26
|
+
{:attr1=>[<value of attr1 in a>,<value of attr1 in b>], :attr2=>[<value of attr2 in a>,<value of attr2 in b>]} if both values are different in a and b.
|
22
27
|
|
23
28
|
Options for differs_from:
|
24
29
|
1. ignore_attributes: This options helps to ignore attributes from the AR objects while comparison.
|
25
|
-
|
26
|
-
a.differs_from b, :ignore_attributes=>[:id, :created_at]
|
30
|
+
a.differs_from b, :ignore_attributes=>[:id, :created_at]
|
27
31
|
|
28
32
|
2. only_attribues: This options helps to compare only the specified attributes.
|
29
|
-
a.differs_from b :only_attributes=> :name
|
33
|
+
a.differs_from b :only_attributes=> :name
|
30
34
|
|
31
35
|
|
32
|
-
|
33
|
-
|
36
|
+
Tests
|
37
|
+
This repo uses very lightweight test-suite 'minitest'
|
38
|
+
To run tests:
|
39
|
+
1. $ bundle install #at root
|
40
|
+
2. $ ruby test/test_difference.rb
|
34
41
|
|
35
42
|
|
36
43
|
License
|
data/difference.gemspec
CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
-
|
22
|
+
s.add_dependency 'activerecord'
|
23
|
+
|
24
|
+
s.add_development_dependency 'minitest'
|
25
|
+
s.add_development_dependency 'sqlite3'
|
23
26
|
# s.add_runtime_dependency "rest-client"
|
24
27
|
end
|
data/lib/difference/version.rb
CHANGED
data/lib/difference.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
.gitkeep
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative 'test_helper'
|
3
|
+
|
4
|
+
class FakeUser < ActiveRecord::Base
|
5
|
+
def self.needs_attr_accessible?
|
6
|
+
ActiveRecord::VERSION::MAJOR == 3
|
7
|
+
end
|
8
|
+
|
9
|
+
if needs_attr_accessible?
|
10
|
+
attr_accessible :name, :address
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestDifference < MiniTest::Test
|
15
|
+
def setup
|
16
|
+
@john = FakeUser.create(:name => 'john', :address => 'NYC')
|
17
|
+
@smith = FakeUser.create(:name => 'smith', :address => 'NYC')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_john_and_smith_not_matching_on_id_and_name
|
21
|
+
assert_equal({:id => [@john.id, @smith.id], :name=>["john", "smith"]}, @john.differs_from(@smith))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_john_and_smith_not_matching_on_name
|
25
|
+
assert_equal({:name=>["john", "smith"]}, @john.differs_from(@smith, :ignore_attributes => [:id, :created_at]))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_john_and_smith_matching_on_address
|
29
|
+
assert_equal({}, @john.differs_from(@smith, :only_attributes => [:address]))
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'sqlite3'
|
4
|
+
|
5
|
+
require_relative '../lib/difference.rb'
|
6
|
+
|
7
|
+
FileUtils.rm_f 'test/setup/db/test.sqlite3'
|
8
|
+
|
9
|
+
ActiveRecord::Base.establish_connection(
|
10
|
+
:adapter => 'sqlite3',
|
11
|
+
:database => './test/setup/db/test.sqlite3'
|
12
|
+
)
|
13
|
+
|
14
|
+
ActiveRecord::Migration.class_eval do
|
15
|
+
create_table :fake_users do |t|
|
16
|
+
t.string :name
|
17
|
+
t.text :address
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: difference
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 967688027
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- 2
|
10
|
+
- alpha
|
11
|
+
version: 1.0.2.alpha
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Manish Puri
|
@@ -15,9 +16,50 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
date: 2014-02-17 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: minitest
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: sqlite3
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
21
63
|
description: This is a simple gem to compare 2 objects of the same class and return a hash of differences
|
22
64
|
email:
|
23
65
|
- manishspuri@gmail.com
|
@@ -29,12 +71,16 @@ extra_rdoc_files: []
|
|
29
71
|
|
30
72
|
files:
|
31
73
|
- .gitignore
|
74
|
+
- .travis.yml
|
32
75
|
- Gemfile
|
33
76
|
- README.rdoc
|
34
77
|
- Rakefile
|
35
78
|
- difference.gemspec
|
36
79
|
- lib/difference.rb
|
37
80
|
- lib/difference/version.rb
|
81
|
+
- test/setup/db/.gitkeep
|
82
|
+
- test/test_difference.rb
|
83
|
+
- test/test_helper.rb
|
38
84
|
homepage: ""
|
39
85
|
licenses: []
|
40
86
|
|
@@ -55,16 +101,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
102
|
none: false
|
57
103
|
requirements:
|
58
|
-
- - "
|
104
|
+
- - ">"
|
59
105
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
106
|
+
hash: 25
|
61
107
|
segments:
|
62
|
-
-
|
63
|
-
|
108
|
+
- 1
|
109
|
+
- 3
|
110
|
+
- 1
|
111
|
+
version: 1.3.1
|
64
112
|
requirements: []
|
65
113
|
|
66
114
|
rubyforge_project: difference
|
67
|
-
rubygems_version: 1.8.
|
115
|
+
rubygems_version: 1.8.17
|
68
116
|
signing_key:
|
69
117
|
specification_version: 3
|
70
118
|
summary: difference between 2 objects
|