couchrest_localised_properties 0.1 → 0.1.1

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.
@@ -41,6 +41,10 @@ While getting and setting values is quite considerably easier, you'll still need
41
41
 
42
42
  == Updates
43
43
 
44
+ === v0.1.1 - 20th April 2011
45
+
46
+ - Updated to use CouchRest Model 1.1.0.beta4 with dirty tracking
47
+
44
48
  === v0.1 - 25th March 2011
45
49
 
46
50
  - First release
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1
1
+ 0.1.1
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.5") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Lown"]
9
- s.date = %q{2011-03-23}
9
+ s.date = %q{2011-04-20}
10
10
  s.description = %q{Add support to CouchRest Model for localised properties.}
11
11
  s.email = %q{me@samlown.com}
12
12
  s.extra_rdoc_files = [
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency("couchrest_model", "~> 1.1.0.beta")
24
+ s.add_dependency("couchrest_model", "~> 1.1.0.beta4")
25
25
  s.add_dependency("i18n", "> 0.3.0")
26
26
  s.add_development_dependency(%q<rspec>, ">= 2.0.0")
27
27
  end
@@ -23,8 +23,10 @@ module CouchRest
23
23
  self[key][k] = prop.cast(self, v)
24
24
  end
25
25
  else
26
+ value = prop.is_a?(String) ? value : prop.cast(self, value)
27
+ couchrest_attribute_will_change!(prop.to_s) if use_dirty? && self[prop.to_s] != value
26
28
  self[key] ||= { }
27
- self[key][I18n.locale.to_s] = prop.is_a?(String) ? value : prop.cast(self, value)
29
+ self[key][I18n.locale.to_s] = value
28
30
  end
29
31
  end
30
32
 
@@ -5,6 +5,7 @@ require File.expand_path('../../spec_helper', __FILE__)
5
5
  class BasicLP < CouchRest::Model::Base
6
6
  use_database DB
7
7
  localised_property :title, String
8
+ localised_property :popularity, Float
8
9
  property :posted_at, DateTime
9
10
  end
10
11
 
@@ -56,22 +57,28 @@ describe "CouchRest LocalisedProperties" do
56
57
  @obj['title']['en'].should eql('Sample Title')
57
58
  end
58
59
 
60
+ it "should call dirty tracking to register the change" do
61
+ @obj.should_receive(:couchrest_attribute_will_change!).with('title')
62
+ @obj.write_localised_attribute('title', "Sample Title")
63
+ end
64
+
65
+ it "should mark record as changed when translation set" do
66
+ @obj.changed?.should be_false
67
+ @obj.title = 'New Title'
68
+ @obj.title_changed?.should be_true
69
+ @obj.changed?.should be_true
70
+ end
71
+
59
72
  describe "with casting" do
60
- before :each do
61
- @prop = mock('Property')
62
- @prop.should_receive(:to_s).and_return('title')
63
- @prop.should_receive(:cast).and_return('the title')
64
- @obj.should_receive(:find_property!).and_return(@prop)
65
- end
66
73
  it "should perform type casting on normal write" do
67
- @prop.should_receive(:is_a?).and_return(false)
68
74
  I18n.locale = 'en'
69
- @obj.write_localised_attribute('title', 'something')
70
- @obj['title']['en'].should eql('the title')
75
+ amount = '32'
76
+ @obj.write_localised_attribute('popularity', amount)
77
+ @obj['popularity']['en'].should eql(32.0)
71
78
  end
72
79
  it "should perform casting on each key when hash sent" do
73
- @prop.should_receive(:cast).and_return('the title') # second time
74
- @obj.write_localised_attribute('title', {'en' => 'title', 'es' => 'título'})
80
+ @obj.write_localised_attribute('popularity', {'en' => '23', 'es' => '32'})
81
+ @obj['popularity']['es'].should eql(32.0)
75
82
  end
76
83
  end
77
84
  end
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- version: "0.1"
8
+ - 1
9
+ version: 0.1.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - Sam Lown
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2011-03-23 00:00:00 +01:00
17
+ date: 2011-04-20 00:00:00 +02:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
@@ -28,8 +29,8 @@ dependencies:
28
29
  - 1
29
30
  - 1
30
31
  - 0
31
- - beta
32
- version: 1.1.0.beta
32
+ - beta4
33
+ version: 1.1.0.beta4
33
34
  type: :runtime
34
35
  version_requirements: *id001
35
36
  - !ruby/object:Gem::Dependency