opium 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/opium/model/dirty.rb +12 -8
- data/lib/opium/version.rb +1 -1
- data/spec/opium/model/dirty_spec.rb +16 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41273455a1d59fc4ccd1bfe03f43f2cdce23384d
|
4
|
+
data.tar.gz: 221b878aba20e3acbc3201986bc0fe0f73c314d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 559adc15de59342f0bb01d4ac5c20a4d6453a2c9211b66b71db2dc324196ae06b87a2db363845a35b2c6589cc3b860814e9c621ab9f985d17bf77ecdee851d6d
|
7
|
+
data.tar.gz: 9ac14b003d4822f3cb0933a41948588febb6165f88215607dfcce491c3c757a4719280089a6ac8faa22168cbf12136a923163fea421048eb498bd10733dff694
|
data/CHANGELOG.md
CHANGED
data/lib/opium/model/dirty.rb
CHANGED
@@ -2,34 +2,38 @@ module Opium
|
|
2
2
|
module Model
|
3
3
|
module Dirty
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
|
6
6
|
included do
|
7
7
|
include ActiveModel::Dirty
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def initialize( attributes = {} )
|
11
11
|
super( attributes ).tap { self.send :clear_changes_information }
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def save( options = {} )
|
15
15
|
super( options ).tap { self.send :changes_applied }
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
def save!( *args )
|
19
|
+
super( *args ).tap { self.send :changes_applied }
|
20
|
+
end
|
21
|
+
|
18
22
|
private
|
19
|
-
|
23
|
+
|
20
24
|
unless defined?(clear_changes_information)
|
21
25
|
def clear_changes_information
|
22
26
|
@previously_changed = ActiveSupport::HashWithIndifferentAccess.new
|
23
27
|
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
|
24
28
|
end
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
unless defined?(changes_applied)
|
28
32
|
def changes_applied
|
29
33
|
@previously_changed = changes
|
30
34
|
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
|
31
|
-
end
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
35
|
-
end
|
39
|
+
end
|
data/lib/opium/version.rb
CHANGED
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Opium::Model::Dirty do
|
4
4
|
let( :model ) { Class.new { def initialize(a = {}); end; def save(o = {}); end; include Opium::Model::Dirty; } }
|
5
|
-
|
5
|
+
|
6
6
|
describe 'instance' do
|
7
7
|
subject { model.new }
|
8
|
-
|
8
|
+
|
9
9
|
it { should respond_to( :changed?, :changed, :changed_attributes ) }
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe 'when included in a model' do
|
13
13
|
before do
|
14
14
|
stub_const( 'Game', Class.new do
|
@@ -19,21 +19,26 @@ describe Opium::Model::Dirty do
|
|
19
19
|
body: "{\"title\":\"Skyrim\"}",
|
20
20
|
headers: {'Content-Type'=>'application/json'}
|
21
21
|
).to_return(
|
22
|
-
body: { objectId: 'abcd1234', createdAt: Time.now.to_s }.to_json,
|
23
|
-
status: 200,
|
24
|
-
headers: { 'Content-Type' => 'application/json', Location: 'https://api.parse.com/1/classes/Game/abcd1234' }
|
22
|
+
body: { objectId: 'abcd1234', createdAt: Time.now.to_s }.to_json,
|
23
|
+
status: 200,
|
24
|
+
headers: { 'Content-Type' => 'application/json', Location: 'https://api.parse.com/1/classes/Game/abcd1234' }
|
25
25
|
)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
subject { Game.new( title: 'Skyrim' ) }
|
29
|
-
|
29
|
+
|
30
30
|
it 'when instantiated, should not be changed' do
|
31
31
|
subject.should_not be_changed
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it 'when saved, should receive #changes_applied' do
|
35
35
|
subject.should receive(:changes_applied)
|
36
36
|
subject.save
|
37
|
-
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'when saved!, should receive #changes_applied' do
|
40
|
+
subject.should receive(:changes_applied)
|
41
|
+
subject.save!
|
42
|
+
end
|
38
43
|
end
|
39
|
-
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Bowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|