frenchy 0.2.8 → 0.2.9

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: 7c33034dadf83afbfbf323dc17f655e06aeafc8b
4
- data.tar.gz: ef363621d4bf7e0ef39b1f6546440effbaa4df38
3
+ metadata.gz: ecf8dc456d1c54c95c08e178b0532c2a34120faf
4
+ data.tar.gz: 2f4852e2d285944e0deb57421bc2d42d7bfc5162
5
5
  SHA512:
6
- metadata.gz: f5d0aeaad2d4b2091764f029fae20a6fa00f2a421fc2753a38607bdda0f031f843c82ca595c4c88b18c0ff18b4de3781e347e293e7ab1a118b9ac9cfe4765864
7
- data.tar.gz: 235fdf96cc08c9bd2690767a2f769a6a0a0bbe4a9cc5cbe1041948ab0cd3340652d18318e1810e96e16b882383e852664960563a98f316669b2c592a29cd9532
6
+ metadata.gz: 4dde73ee708851cccb34da13e58db45c135f6ef4afbd7fb653ce1586519162e4028ec149c4f6f67aa9b80bae1f80f275992e4bf2098361a88010a4f5a556d713
7
+ data.tar.gz: e25d72b1eb1c487956cc4a72d29dd979c5521ab8e41328ee7278411d9387d6450a46f6ca89d38985fd2186213e2bea2c003c94f5b17f57d5664812e12edef0e1
@@ -30,6 +30,11 @@ if defined?(ActiveModel)
30
30
  @model.to_s.pluralize
31
31
  end
32
32
  end
33
+
34
+ define_method(:record_key) do
35
+ raise(Frenchy::Error, "No primary key is specified") unless respond_to?(:to_param)
36
+ "#{self.class.table_name}/#{to_param}"
37
+ end
33
38
  end
34
39
  end
35
40
  end
@@ -1,3 +1,3 @@
1
1
  module Frenchy
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
@@ -1,11 +1,24 @@
1
1
  require "spec_helper"
2
2
 
3
3
  class FakeModel
4
+ include Frenchy::Model
4
5
  include Frenchy::Veneer
5
6
 
6
7
  veneer model: "real_model"
8
+
9
+ key :id
10
+
11
+ field :id, type: "integer"
7
12
  end
8
13
 
14
+ class FakeModelTwo
15
+ include Frenchy::Model
16
+ include Frenchy::Veneer
17
+ veneer model: "real_model_two"
18
+ field :id, type: "integer"
19
+ end
20
+
21
+
9
22
  describe Frenchy::Veneer do
10
23
  describe ".model_name" do
11
24
  it "returns an instance of ActiveModel::Name" do
@@ -15,9 +28,27 @@ describe Frenchy::Veneer do
15
28
  it "provides the expected model name" do
16
29
  expect(FakeModel.model_name.to_s).to eql("RealModel")
17
30
  end
31
+ end
18
32
 
33
+ describe ".table_name" do
19
34
  it "provides the expected table name" do
20
35
  expect(FakeModel.table_name).to eql("real_models")
21
36
  end
22
37
  end
38
+
39
+ describe "#record_key" do
40
+ it "provides the expected key when new" do
41
+ expect(FakeModel.new.record_key).to eql("real_models/")
42
+ end
43
+
44
+ it "provides the expected key when existing" do
45
+ expect(FakeModel.new({id: 12345}).record_key).to eql("real_models/12345")
46
+ end
47
+
48
+ it "raises an error when no to_param is available" do
49
+ expect do
50
+ FakeModelTwo.new({id: 12345}).record_key
51
+ end.to raise_error(Frenchy::Error)
52
+ end
53
+ end
23
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frenchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Coene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  requirements: []
181
181
  rubyforge_project:
182
- rubygems_version: 2.2.2
182
+ rubygems_version: 2.4.5
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: Opinionated JSON API modeling framework for Ruby.