spyke 2.0.1 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e544879dfca5f90ba78e73e05f7370170445fff8
4
- data.tar.gz: 991433596aec9c35a3f7065d0c71dcb798c58f12
3
+ metadata.gz: 2ce71952fe595064f132a92bbbc41179614be927
4
+ data.tar.gz: bdf0fc8ed096c28303c3014ddcb588a666a39a04
5
5
  SHA512:
6
- metadata.gz: 1f9f7d0219671080bb9d91e083d763eb10c15ed624d77c40ff5691c0e3e0880960d7d2b97175473213d8df290ccfdde20333a1e2721301c7720a17e0cb55bf9d
7
- data.tar.gz: 4eed190ef156ea97ea07e4d0911a98d75f48f70d7692f3a1d908bc3126c92df064adb7ae33f2738a27342cfbcdbbf8e0a8b047f63f70017b3bd501673090fd8b
6
+ metadata.gz: 8799dbc60fb64c096241990fb35d53d802dcc83c98a45f71e1573649261b3b11ea8558af102e335ed7eabde7678056bc13912984de7a7e51665d75be9cae6f82
7
+ data.tar.gz: df55a3f1dc825c5a10d3e0c142b42bed0739cb942e8c32bc2da501a9215f897200fa3fd6a162cdcebb19241369868fafd802dd7ab5349f9f0a858e2d0b63fc1f
data/README.md CHANGED
@@ -128,16 +128,16 @@ Post.find(4) # => GET http://api.com/posts/4
128
128
 
129
129
  ### Custom requests
130
130
 
131
- Custom request methods and the `using` scope methods allow you to
131
+ Custom request methods and the `with` scope methods allow you to
132
132
  perform requests for non-REST actions:
133
133
 
134
- The `.using` scope:
134
+ The `.with` scope:
135
135
 
136
136
  ```ruby
137
- Post.using('posts/recent') # => GET http://api.com/posts/recent
138
- Post.using(:recent) # => GET http://api.com/posts/recent
139
- Post.using(:recent).where(status: 'draft') # => GET http://api.com/posts/recent?status=draft
140
- Post.using(:recent).post # => POST http://api.com/posts/recent
137
+ Post.with('posts/recent') # => GET http://api.com/posts/recent
138
+ Post.with(:recent) # => GET http://api.com/posts/recent
139
+ Post.with(:recent).where(status: 'draft') # => GET http://api.com/posts/recent?status=draft
140
+ Post.with(:recent).post # => POST http://api.com/posts/recent
141
141
  ```
142
142
 
143
143
  Custom requests from instance:
@@ -48,9 +48,14 @@ module Spyke
48
48
  attributes[:id] = value if value.present?
49
49
  end
50
50
 
51
+ def hash
52
+ id.hash
53
+ end
54
+
51
55
  def ==(other)
52
- other.is_a?(Spyke::Base) && id == other.id
56
+ other.instance_of?(self.class) && id? && id == other.id
53
57
  end
58
+ alias :eql? :==
54
59
 
55
60
  def inspect
56
61
  "#<#{self.class}(#{uri}) id: #{id.inspect} #{inspect_attributes}>"
@@ -18,7 +18,7 @@ module Spyke
18
18
  relation
19
19
  end
20
20
 
21
- def using(uri)
21
+ def with(uri)
22
22
  if uri.is_a? Symbol
23
23
  @options[:uri] = File.join @options[:uri], uri.to_s
24
24
  else
@@ -7,7 +7,7 @@ module Spyke
7
7
 
8
8
  module ClassMethods
9
9
  delegate :where, :build, :any?, :empty?, to: :all
10
- delegate :using, to: :all
10
+ delegate :with, to: :all
11
11
 
12
12
  def all
13
13
  current_scope || Relation.new(self, uri: uri)
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '2.0.1'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -63,6 +63,18 @@ module Spyke
63
63
  assert_equal Recipe.new(id: 2, title: 'Fish'), Recipe.new(id: 2, title: 'Fish')
64
64
  refute_equal Recipe.new(id: 2, title: 'Fish'), Recipe.new(id: 1, title: 'Fish')
65
65
  refute_equal Recipe.new(id: 2, title: 'Fish'), 'not_a_spyke_object'
66
+ refute_equal Recipe.new(id: 2, title: 'Fish'), Image.new(id: 2, title: 'Fish')
67
+ refute_equal Recipe.new, Recipe.new
68
+ refute_equal StepImage.new(id: 1), Image.new(id: 1)
69
+ end
70
+
71
+ def test_uniqueness
72
+ recipe_1 = Recipe.new(id: 1)
73
+ recipe_2 = Recipe.new(id: 1)
74
+ recipe_3 = Recipe.new(id: 2)
75
+ image_1 = Image.new(id: 2)
76
+ records = [recipe_1, recipe_2, recipe_3, image_1]
77
+ assert_equal [recipe_1, recipe_3, image_1], records.uniq
66
78
  end
67
79
 
68
80
  def test_explicit_attributes
@@ -4,38 +4,38 @@ module Spyke
4
4
  class CustomRequestTest < MiniTest::Test
5
5
  def test_custom_get_request_from_class
6
6
  endpoint = stub_request(:get, 'http://sushi.com/recipes/recent').to_return_json(result: [{ id: 1, title: 'Bread' }])
7
- recipes = Recipe.using('/recipes/recent').get
7
+ recipes = Recipe.with('/recipes/recent').get
8
8
  assert_equal %w{ Bread }, recipes.map(&:title)
9
9
  assert_requested endpoint
10
10
  end
11
11
 
12
12
  def test_custom_put_request_from_class
13
13
  endpoint = stub_request(:put, 'http://sushi.com/recipes/publish_all')
14
- Recipe.using('/recipes/publish_all').put
14
+ Recipe.with('/recipes/publish_all').put
15
15
  assert_requested endpoint
16
16
  end
17
17
 
18
18
  def test_custom_request_with_prepended_scope
19
19
  endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
20
- Recipe.published.using('/recipes/recent').to_a
20
+ Recipe.published.with('/recipes/recent').to_a
21
21
  assert_requested endpoint
22
22
  end
23
23
 
24
24
  def test_custom_request_with_appended_scope
25
25
  endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
26
- Recipe.using('/recipes/recent').published.to_a
26
+ Recipe.with('/recipes/recent').published.to_a
27
27
  assert_requested endpoint
28
28
  end
29
29
 
30
30
  def test_custom_request_with_symbol_and_appended_scope
31
31
  endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
32
- Recipe.using(:recent).published.to_a
32
+ Recipe.with(:recent).published.to_a
33
33
  assert_requested endpoint
34
34
  end
35
35
 
36
36
  def test_create_on_custom_request
37
37
  endpoint = stub_request(:post, 'http://sushi.com/recipes/recent').with(body: { recipe: { status: 'published' } })
38
- Recipe.using(:recent).published.create
38
+ Recipe.with(:recent).published.create
39
39
  assert_requested endpoint
40
40
  end
41
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport