druthers 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTc3MmFjMzEzOTdhODIzODUxZTA4ZWY5OTY5NTNmYWU1YmQwOTk5Nw==
4
+ Y2Q2ODBjN2ViMjc4NmQ0MzI3NzBjYTBhYjgzMDFmNDlkNjRmYmJmOQ==
5
5
  data.tar.gz: !binary |-
6
- YzBlNDhiMDJiMzk3ZTBjZjMwNWYwOGI1NmRmODkxZmVjZDM0YjFlYg==
7
- !binary "U0hBNTEy":
6
+ MjkzYTgzOWJhYmUyMTgzMTQ4NDYwYjczMzUxNzkxNDUxNDZkZDJhNQ==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDQ1YjZhYzhiY2QwMDJkNjA2NmRkOGMxNjZmODMyNWVkYTg4YzkzNmZmZjRi
10
- MTIwYjM1MjMxOTE1M2E4ZmVjNjBjODg4ZmEyYjk0MzgyZjRkN2M4NmYyNmI2
11
- NDljZjhhNzYyMDM5YTJlMTViYjdlOWIyNzk0OTNiYjJjM2MzZDI=
9
+ NTM4MmRmNzM0MTI1YjgzMGVmYjZhZWQ4NDdkN2JjN2Y2MWRmYmMxNWExYTgy
10
+ ZGJhYmRiNmI5NzFjOTUyOGYyNThmZGY0OTNlODU4ZjIyMjg2YWZlZGM4MGMx
11
+ MmI1N2E5NjllMzBlNTNjZTcwMjY0YjQzZWRiNWY0MzM3YTg0Yjg=
12
12
  data.tar.gz: !binary |-
13
- ZGQ3MDdhZDg2ZTBkYjMyMTg0MzI2NTJhNjU5YWI5OWM3YmJhN2ZiM2I3Y2Iz
14
- YzZkMDZjYjVhMzk5NzczNDUyOGIwYWRjMjIzMGY5Y2VlMzllOTA3MTYwYWRm
15
- MDU0ZDk1MGU0M2U4NmVlOGNlMTg5ODNjNmIxZjMyZTQxN2Q0M2M=
13
+ MzAxNWMyZDMxMDdiOTE2YzIzYmFkODA0MmNhM2ZlMmM2NjEzODJhYjcxMGJm
14
+ NDBhZGE2MmVmOGMwM2ZjMTUxYmM0ZDcyNzg2YzVmYWMzMmU5NTZjZGI2MGQx
15
+ MWQ0NjdjNjBjY2JkNTcxOTNmNWEyMzIyYTUyZTZjOTRlYjVhZmI=
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
data/.travis.yml CHANGED
@@ -5,6 +5,7 @@ rvm:
5
5
  - 1.9.3
6
6
 
7
7
  gemfile:
8
+ - ci/Gemfile.rails-4.1.x
8
9
  - ci/Gemfile.rails-4.0.x
9
10
  - ci/Gemfile.rails-3.2.x
10
11
 
data/CHANGELOG.md CHANGED
@@ -1,9 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.0.3
4
+
5
+ * Rails 4.1 is supported
6
+
7
+ * Fixes a bug where serialized values weren't cached properly. Thanks for the
8
+ [description, fix and tests](https://github.com/mceachen/druthers/pull/2),
9
+ [JKillian](https://github.com/JKillian)!
10
+
3
11
  ## v0.0.2
4
12
 
5
- ```def_druthers``` only add methods if they aren't already defined now.
13
+ * ```def_druthers``` will only add getter and setters if they aren't already defined
6
14
 
7
15
  ## v0.0.1
8
16
 
9
- First Post!
17
+ Druthers is born. YOU WILL LOVE IT
data/README.md CHANGED
@@ -23,7 +23,7 @@ As opposed to ```rails-settings``` and forks, ```method_missing``` isn't used an
23
23
  ## Supported versions
24
24
 
25
25
  The latest versions of
26
- * Rails 3.2 & 4.0
26
+ * Rails 3.2, 4.0, & 4.1
27
27
  * Ruby 1.9.3 & 2.0.0
28
28
  * SQLite, MySQL, and PostgreSQL
29
29
 
@@ -43,11 +43,13 @@ class Setting < ActiveRecord::Base
43
43
  serialize :value
44
44
 
45
45
  # This will be used as the value of `Setting.quest` if it is not set.
46
- def default_quest
46
+ def self.default_quest
47
47
  "to find the holy grail"
48
48
  end
49
49
 
50
- # This validation will be only run for instances whose key == "favourite_color":
50
+ # This validation will be only run for instances whose key == "favourite_color"
51
+ # Note that this isn't a class method, as the validation needs access to the
52
+ # instance value.
51
53
  def validate_favourite_colour
52
54
  add_error("we're right out of teal, sorry") if value == "teal"
53
55
  end
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec :path => '..'
3
3
 
4
- # rspec-rails reverts to 2.3.1 (old and broken) unless you fetch the whole rails enchilada:
5
- gem 'rails', '~> 4.0.0'
4
+ gem 'activerecord', '~> 4.0.0'
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => '..'
3
+
4
+ gem 'activerecord', '~> 4.1.0.beta1'
@@ -38,7 +38,10 @@ module Druthers
38
38
  obj.update_attributes!(value: value)
39
39
  end
40
40
  # Only update the cache if the update! succeeded:
41
- druthers_cache.write(key, value)
41
+ # Note that we cached the obj.value, rather than the value, to make sure
42
+ # returned values are consistent with the serializer's result.
43
+ # See https://github.com/mceachen/druthers/pull/2
44
+ druthers_cache.write(key, obj.value)
42
45
  obj
43
46
  end
44
47
 
@@ -1,3 +1,3 @@
1
1
  module Druthers
2
- VERSION = Gem::Version.new("0.0.2")
2
+ VERSION = Gem::Version.new("0.0.3")
3
3
  end
data/test/setting_test.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'minitest_helper'
2
2
 
3
3
  describe Setting do
4
- before :each do
4
+ before do
5
+ Setting.druthers_cache.clear
5
6
  Setting.delete_all
6
7
  end
7
8
 
@@ -52,5 +53,10 @@ describe Setting do
52
53
  Setting.hashish = h
53
54
  Setting.where(key: 'hashish').first.value.must_equal h
54
55
  end
56
+
57
+ it 'returns serialized value correctly' do
58
+ Setting.change = 'foo'
59
+ Setting.change.must_equal 'bar'
60
+ end
55
61
  end
56
62
  end
data/test/test_models.rb CHANGED
@@ -8,8 +8,7 @@ ActiveRecord::Schema.define(:version => 0) do
8
8
  end
9
9
 
10
10
  class Setting < ActiveRecord::Base
11
- def_druthers :quest, :favourite_colour, :things, :hashish
12
- serialize :value
11
+ def_druthers :quest, :favourite_colour, :things, :hashish, :change
13
12
 
14
13
  def self.default_quest
15
14
  "to find the holy grail"
@@ -22,4 +21,18 @@ class Setting < ActiveRecord::Base
22
21
  def validate_favourite_colour
23
22
  errors.add(:value, "invalid is invalid WERD") if value == "invalid"
24
23
  end
24
+
25
+ class CustomSerialize
26
+ def self.load(val)
27
+ ActiveRecord::Coders::YAMLColumn.new.load(val)
28
+ end
29
+
30
+ def self.dump(val)
31
+ val = 'bar' if val == 'foo'
32
+ ActiveRecord::Coders::YAMLColumn.new.dump(val)
33
+ end
34
+ end
35
+
36
+ serialize :value, CustomSerialize
37
+
25
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: druthers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew McEachen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-14 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -152,6 +152,7 @@ files:
152
152
  - Rakefile
153
153
  - ci/Gemfile.rails-3.2.x
154
154
  - ci/Gemfile.rails-4.0.x
155
+ - ci/Gemfile.rails-4.1.x
155
156
  - druthers.gemspec
156
157
  - lib/druthers.rb
157
158
  - lib/druthers/def.rb
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  requirements: []
183
184
  rubyforge_project:
184
- rubygems_version: 2.0.3
185
+ rubygems_version: 2.2.0
185
186
  signing_key:
186
187
  specification_version: 4
187
188
  summary: ''