minimapper 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,7 @@ The API may not be entirely stable yet and there are probably edge cases that ar
19
19
 
20
20
  ### Compatibility
21
21
 
22
- This gem is tested against all major rubies in both 1.8 and 1.9, see [.travis.yml](https://github.com/joakimk/minimapper/blob/master/.travis.yml). For each ruby version, the SQL mappers are tested against SQLite3, PostgreSQL and MySQL.
22
+ This gem is tested against all major rubies in 1.8, 1.9 and 2.0, see [.travis.yml](https://github.com/joakimk/minimapper/blob/master/.travis.yml). For each ruby version, the SQL mappers are tested against SQLite3, PostgreSQL and MySQL.
23
23
 
24
24
  ### Only the most basic API
25
25
 
@@ -44,6 +44,8 @@ Or install it yourself as:
44
44
 
45
45
  $ gem install minimapper
46
46
 
47
+ You also need the `activemodel` gem if you use Minimapper::Entity and not only Minimapper::Entity::Core.
48
+
47
49
  Please avoid installing directly from the github repository. Code will be pushed there that might fail in [CI](https://travis-ci.org/#!/joakimk/minimapper/builds) (because testing all permutations of ruby versions and databases locally isn't practical). Gem releases are only done when CI is green.
48
50
 
49
51
  ## Usage
@@ -142,7 +144,7 @@ Validations on uniqueness can't be implemented on the entity, because they need
142
144
 
143
145
  Therefore, the ActiveRecord mapper will copy over any record errors to the entity when attempting to create or update.
144
146
 
145
- You would add these validations to the record itself, like:
147
+ Add these validations to the record itself, like:
146
148
 
147
149
  ``` ruby
148
150
  class User < ActiveRecord::Base
@@ -150,7 +152,7 @@ class User < ActiveRecord::Base
150
152
  end
151
153
  ```
152
154
 
153
- Note that calling `valid?` on the entity will not access the database. Errors copied over from the record will remain until the next attempt to create or update.
155
+ Note that just calling `valid?` on the entity will not access the database. Errors copied over from the record will remain until the next attempt to create or update.
154
156
 
155
157
  So an entity that wouldn't be unique in the database will be `valid?` before you attempt to create it. And after you attempt to create it, the entity will not be `valid?` even after assigning a new value, until you attempt to create it again.
156
158
 
@@ -280,6 +282,7 @@ Robert "Uncle Bob" Martin:
280
282
 
281
283
  ### Apps
282
284
 
285
+ * About 4 people at [Barsoom](http://barsoom.se/) are currently working full time on building a rails app that uses minimapper. We'll be extending minimapper as we go.
283
286
  * The deploy status app that minimapper was extracted from: [https://github.com/joakimk/deployer](https://github.com/joakimk/deployer)
284
287
 
285
288
  ## Contributing
@@ -1,5 +1,9 @@
1
- # The core entity API required by minimapper. If your entity
2
- # class implements this API, it should work with the data mappers.
1
+ # The core entity API required by minimapper. If your entity class implements
2
+ # this API, it should work with the data mappers.
3
+
4
+ # IMPORTANT: This module should only implement the minimal interface needed
5
+ # to talk to the data mappers. If a method isn't used by the mappers it should
6
+ # not be in this file.
3
7
 
4
8
  module Minimapper
5
9
  module Entity
@@ -12,8 +12,8 @@ module Minimapper
12
12
  extend ActiveModel::Naming
13
13
  include ActiveModel::Validations
14
14
 
15
- # Must be later than ActiveModel::Validations so
16
- # it can call it with super.
15
+ # Must be added after ActiveModel::Validations so our
16
+ # validations can call ActiveModel's with `super`.
17
17
  include ValidationsWithMapperErrors
18
18
  end
19
19
  end
@@ -16,6 +16,14 @@ module Minimapper
16
16
  new_attributes.each_pair { |name, value| self.send("#{name}=", value) }
17
17
  end
18
18
 
19
+ def ==(other)
20
+ super || (
21
+ other.instance_of?(self.class) &&
22
+ self.id &&
23
+ other.id == self.id
24
+ )
25
+ end
26
+
19
27
  def self.included(klass)
20
28
  klass.send(:include, Minimapper::Entity::Rails)
21
29
  klass.send(:extend, Minimapper::Entity::Attributes)
@@ -1,3 +1,3 @@
1
1
  module Minimapper
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -5,6 +5,10 @@ class BasicEntity
5
5
  attr_accessor :one, :two
6
6
  end
7
7
 
8
+ class OtherEntity
9
+ include Minimapper::Entity::Core
10
+ end
11
+
8
12
  describe Minimapper::Entity::Core do
9
13
  it "can get and set an attributes hash" do
10
14
  entity = BasicEntity.new
@@ -47,7 +51,7 @@ describe Minimapper::Entity::Core do
47
51
  end
48
52
 
49
53
  describe "#mapper_errors=" do
50
- it "makes it invalid if present" do
54
+ it "makes the mapper invalid if present" do
51
55
  entity = BasicEntity.new
52
56
  entity.mapper_errors = [ [:one, "bad"] ]
53
57
  entity.valid?.should be_false
data/unit/entity_spec.rb CHANGED
@@ -103,3 +103,40 @@ describe Minimapper::Entity, "self.column_names" do
103
103
  TestProject.column_names.should == [ "id", "created_at", "updated_at", "title" ]
104
104
  end
105
105
  end
106
+
107
+ describe Minimapper::Entity, "#==" do
108
+ it "is equal to the exact same instance" do
109
+ entity = build_entity(TestUser, nil)
110
+ entity.should == entity
111
+ end
112
+
113
+ it "is equal to another instance if class and id matches" do
114
+ entity = build_entity(TestUser, 123)
115
+ other_entity = build_entity(TestUser, 123)
116
+ entity.should == other_entity
117
+ end
118
+
119
+ it "is not equal to another instance if there is no id" do
120
+ entity = build_entity(TestUser, nil)
121
+ other_entity = build_entity(TestUser, nil)
122
+ entity.should_not == other_entity
123
+ end
124
+
125
+ it "is not equal to another instance if ids do not match" do
126
+ entity = build_entity(TestUser, 123)
127
+ other_entity = build_entity(TestUser, 456)
128
+ entity.should_not == other_entity
129
+ end
130
+
131
+ it "is not equal to another instance if classes do not match" do
132
+ entity = build_entity(TestUser, 123)
133
+ other_entity = build_entity(TestProject, 123)
134
+ entity.should_not == other_entity
135
+ end
136
+
137
+ def build_entity(klass, id)
138
+ entity = klass.new
139
+ entity.id = id
140
+ entity
141
+ end
142
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-20 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70108741422080 !ruby/object:Gem::Requirement
16
+ requirement: &70153436310520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70108741422080
24
+ version_requirements: *70153436310520
25
25
  description: A minimalistic way of separating your models from ORMs like ActiveRecord.
26
26
  email:
27
27
  - joakim.kolsjo@gmail.com
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: 3446705768728463359
80
+ hash: 3918684014874405558
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: 3446705768728463359
89
+ hash: 3918684014874405558
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.5