ohm 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcac01f4679b94c4e17d2ee417f59887a8a41f62
4
- data.tar.gz: 5fba56af15af361a22fd0cd6df37adf9bc9beaf3
3
+ metadata.gz: f4d772d265943ece2cb2474ffffe91ca507ea015
4
+ data.tar.gz: e12bcab718e57af58ecd4084db153d22bc17158a
5
5
  SHA512:
6
- metadata.gz: c011955d15f026470d4af58e1b4d96be6b685bee79aa3b85247640bc700268d80fb7ed3f258ac2055fea7fc0ff8bd2dd4b07869b466b5cd89acbfa03143c8bee
7
- data.tar.gz: 7e7ed6334f0db7446262362a49540cee4bbce18ff1163992854dd6faac6cb7f99147f1b753552fdf4aa4ff84dbd678fb8b9ba19951a0ef4b7f640b2eaa35b857
6
+ metadata.gz: e64574ab2442f7bce423f4545fe2e07bf029533e8e6a10eb56d2f86642d48e94d0b36e9f076f9658adc57fda1f9f9cf803b88209b8c5cdce63182238cfb85eea
7
+ data.tar.gz: 2e9378f29c6f884c8b28f19d94ca208188a06b1324898d2bec0d2a63da2d14c8e85224a5aec34be90e7c0007ee59080fdbf827e2434cd7325efd3ef2ef51890e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 3.0.2
2
+
3
+ - Fix bug created the wrong keys when indexing floats.
4
+
5
+ As reported by @slowernet, if an indexed attribute was assigned a
6
+ real value with 0 fractional part (eg. 3.0), the `tostring` function
7
+ in lua truncated the value to an integer. As a result, the index
8
+ was created with the wrong key (Model:indices:attribute:3, instead
9
+ of Model:indices:attribute:3.0). The fix is to convert all values
10
+ to strings before sending them to the Lua script.
11
+
1
12
  ## 3.0.1
2
13
 
3
14
  - Adapt Lua scripts to Redis unstable.
data/lib/ohm.rb CHANGED
@@ -15,7 +15,7 @@ module Ohm
15
15
  #
16
16
  # MissingID:
17
17
  #
18
- # Comment.new.id # => Error
18
+ # Comment.new.id # => nil
19
19
  # Comment.new.key # => Error
20
20
  #
21
21
  # Solution: you need to save your model first.
@@ -1334,10 +1334,10 @@ module Ohm
1334
1334
  #
1335
1335
  def save
1336
1336
  indices = {}
1337
- model.indices.each { |field| indices[field] = Array(send(field)) }
1337
+ model.indices.each { |field| indices[field] = Array(send(field)).map(&:to_s) }
1338
1338
 
1339
1339
  uniques = {}
1340
- model.uniques.each { |field| uniques[field] = send(field) }
1340
+ model.uniques.each { |field| uniques[field] = send(field).to_s }
1341
1341
 
1342
1342
  features = {
1343
1343
  "name" => model.name
data/lib/ohm/lua/save.lua CHANGED
@@ -57,7 +57,7 @@ end
57
57
  local function index(model, indices)
58
58
  for field, enum in pairs(indices) do
59
59
  for _, val in ipairs(enum) do
60
- local key = model.name .. ":indices:" .. field .. ":" .. tostring(val)
60
+ local key = model.name .. ":indices:" .. field .. ":" .. val
61
61
 
62
62
  redis.call("SADD", model.key .. ":_indices", key)
63
63
  redis.call("SADD", key, model.id)
@@ -78,7 +78,7 @@ end
78
78
  local function unique(model, uniques)
79
79
  for field, value in pairs(uniques) do
80
80
  local key = model.name .. ":uniques:" .. field
81
- local val = tostring(value)
81
+ local val = value
82
82
 
83
83
  redis.call("HSET", model.key .. ":_uniques", key, val)
84
84
  redis.call("HSET", key, val, model.id)
@@ -99,7 +99,7 @@ local function verify(model, uniques)
99
99
 
100
100
  for field, value in pairs(uniques) do
101
101
  local key = model.name .. ":uniques:" .. field
102
- local id = redis.call("HGET", key, tostring(value))
102
+ local id = redis.call("HGET", key, value)
103
103
 
104
104
  if id and id ~= tostring(model.id) then
105
105
  duplicates[#duplicates + 1] = field
data/ohm.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ohm"
3
- s.version = "3.0.1"
3
+ s.version = "3.0.2"
4
4
  s.summary = %{Object-hash mapping library for Redis.}
5
5
  s.description = %Q{Ohm is a library that allows to store an object in Redis, a persistent key-value database. It has very good performance.}
6
6
  s.authors = ["Michel Martens", "Damian Janowski", "Cyril David"]
data/test/indices.rb CHANGED
@@ -124,4 +124,15 @@ scope do
124
124
 
125
125
  assert_equal nil, Node.with(:available, true)
126
126
  end
127
+
128
+ test "float to string" do
129
+ u1 = User.create(:email => "foo", :update => 3.0)
130
+ u2 = User.create(:email => "bar", :update => 3)
131
+
132
+ assert User.find(:update => 3.0).include?(u1)
133
+ assert User.find(:update => 3).include?(u2)
134
+
135
+ assert !User.find(:update => 3.0).include?(u2)
136
+ assert !User.find(:update => 3).include?(u1)
137
+ end
127
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-04-14 00:00:00.000000000 Z
13
+ date: 2016-04-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redic