spyke 1.8.9 → 1.8.10

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: 0b73653b9952f7257a838b16b11abc70770ce471
4
- data.tar.gz: 3f753f7c24bcaad6bc5365a2721a28e5b1df99fc
3
+ metadata.gz: cb655efdf295f174e10b37f5893a28c53aa329f1
4
+ data.tar.gz: f7fbe0a4cb68f336f4d5d62af2dc726447dc4b74
5
5
  SHA512:
6
- metadata.gz: 40e9090eed648f8a51d6af63ad3e1476b9d64e5e054cd90c42810952670c747e3cc1af14af3ba0b31dedf981257b097b368c6225ca9f00d136ab1fd3b197e815
7
- data.tar.gz: 97b830a87cbec15d5f4c74226b0a60841b81b9b9e46a6e60a6b3c4ca0d27f19331845c58ccf3a2d9bbc7103d588b9fbbc48d613c95415e2be0dc8a55dd6a51b9
6
+ metadata.gz: 03dc96bfc86a3719c9872104b2c93d7a9b9b3627c39fe8400e9fd11b9c59a7aa69bb44bac4d22abee982f589f8399b9c9510f4856fbf8372ce10d71b07ec7243
7
+ data.tar.gz: 728e5be62a2edddcc6b8ddab44f98146aacdda3b82157f5175293517cf7ea0eb917ff50d005f129909d9783ce251119b595562a07fb94072a13dd45715797cdb
data/README.md CHANGED
@@ -112,16 +112,16 @@ You can specify custom URIs on both the class and association level:
112
112
 
113
113
  ```ruby
114
114
  class User < Spyke::Base
115
- uri '/v1/users/(:id)' # id optional, both /v1/users and /v1/users/4 are valid
115
+ uri 'people/(:id)' # id optional, both /people and /people/4 are valid
116
116
 
117
- has_many :posts, uri: '/posts/for_user/:user_id' # user_id is required
117
+ has_many :posts, uri: 'posts/for_user/:user_id' # user_id is required
118
118
  has_one :image, uri: nil # only use embedded JSON
119
119
  end
120
120
 
121
121
  class Post < Spyke::Base
122
122
  end
123
123
 
124
- user = User.find(3) # => GET http://api.com/v1/users/3
124
+ user = User.find(3) # => GET http://api.com/people/3
125
125
  user.image # Will only use embedded JSON and never call out to api
126
126
  user.posts # => GET http://api.com/posts/for_user/3
127
127
  Post.find(4) # => GET http://api.com/posts/4
@@ -3,7 +3,7 @@ module Spyke
3
3
  class BelongsTo < Association
4
4
  def initialize(*args)
5
5
  super
6
- @options.reverse_merge!(uri: "/#{@name.to_s.pluralize}/:id", foreign_key: "#{klass.model_name.param_key}_id")
6
+ @options.reverse_merge!(uri: "#{@name.to_s.pluralize}/:id", foreign_key: "#{klass.model_name.param_key}_id")
7
7
  @params[:id] = parent.try(foreign_key)
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module Spyke
3
3
  class HasMany < Association
4
4
  def initialize(*args)
5
5
  super
6
- @options.reverse_merge!(uri: "/#{parent.class.model_name.plural}/:#{foreign_key}/#{@name}/(:id)")
6
+ @options.reverse_merge!(uri: "#{parent.class.model_name.plural}/:#{foreign_key}/#{@name}/(:id)")
7
7
  @params[foreign_key] = parent.id
8
8
  end
9
9
 
@@ -3,7 +3,7 @@ module Spyke
3
3
  class HasOne < Association
4
4
  def initialize(*args)
5
5
  super
6
- @options.reverse_merge!(uri: "/#{parent.class.model_name.plural}/:#{foreign_key}/#{@name}")
6
+ @options.reverse_merge!(uri: "#{parent.class.model_name.plural}/:#{foreign_key}/#{@name}")
7
7
  @params[foreign_key] = parent.id
8
8
  end
9
9
  end
@@ -10,10 +10,20 @@ module Spyke
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- def attributes(*args)
14
- args.each do |attr|
15
- define_method attr do
16
- attribute(attr)
13
+ # By adding instance methods via an included module,
14
+ # they become overridable with "super".
15
+ # http://thepugautomatic.com/2013/dsom/
16
+ def attributes(*names)
17
+ unless @spyke_instance_method_container
18
+ @spyke_instance_method_container = Module.new
19
+ include @spyke_instance_method_container
20
+ end
21
+
22
+ @spyke_instance_method_container.module_eval do
23
+ names.each do |name|
24
+ define_method(name) do
25
+ attribute(name)
26
+ end
17
27
  end
18
28
  end
19
29
  end
data/lib/spyke/http.rb CHANGED
@@ -73,7 +73,7 @@ module Spyke
73
73
  end
74
74
 
75
75
  def default_uri
76
- "/#{model_name.plural}/(:id)"
76
+ "#{model_name.plural}/(:id)"
77
77
  end
78
78
  end
79
79
 
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '1.8.9'
2
+ VERSION = '1.8.10'
3
3
  end
@@ -70,13 +70,28 @@ module Spyke
70
70
  recipe = Recipe.new
71
71
  assert_equal nil, recipe.title
72
72
  assert_raises NoMethodError do
73
- recipe.description
73
+ recipe.not_set
74
74
  end
75
75
 
76
76
  recipe = Recipe.new(title: 'Fish')
77
77
  assert_equal 'Fish', recipe.title
78
78
  end
79
79
 
80
+ def test_super_with_explicit_attributes
81
+ assert_equal nil, Recipe.new.description
82
+ end
83
+
84
+ def test_inheriting_explicit_attributes
85
+ assert_equal nil, Image.new.description
86
+ assert_equal nil, Image.new.caption
87
+ assert_raises NoMethodError do
88
+ Image.new.note
89
+ end
90
+ assert_equal nil, StepImage.new.description
91
+ assert_equal nil, StepImage.new.caption
92
+ assert_equal nil, StepImage.new.note
93
+ end
94
+
80
95
  def test_converting_files_to_faraday_io
81
96
  Faraday::UploadIO.stubs(:new).with('/photo.jpg', 'image/jpeg').returns('UploadIO')
82
97
  file = mock
@@ -96,7 +111,7 @@ module Spyke
96
111
 
97
112
  def test_inspect
98
113
  recipe = Recipe.new(id: 2, title: 'Pizza', description: 'Delicious')
99
- assert_equal '#<Recipe(/recipes/2) id: 2 title: "Pizza" description: "Delicious">', recipe.inspect
114
+ assert_equal '#<Recipe(recipes/2) id: 2 title: "Pizza" description: "Delicious">', recipe.inspect
100
115
  end
101
116
 
102
117
  def test_rejecting_wrong_number_of_args
data/test/orm_test.rb CHANGED
@@ -156,5 +156,16 @@ module Spyke
156
156
  RecipeImage.where(recipe_id: 1).destroy
157
157
  assert_requested endpoint
158
158
  end
159
+
160
+ def test_relative_uris
161
+ previous = Spyke::Config.connection.url_prefix
162
+ Spyke::Config.connection.url_prefix = 'http://sushi.com/api/v2/'
163
+
164
+ endpoint = stub_request(:get, 'http://sushi.com/api/v2/recipes')
165
+ Recipe.all.to_a
166
+ assert_requested endpoint
167
+
168
+ Spyke::Config.connection.url_prefix = previous
169
+ end
159
170
  end
160
171
  end
@@ -3,12 +3,12 @@ class Recipe < Spyke::Base
3
3
  has_many :gallery_images, class_name: 'Image'
4
4
  has_one :image
5
5
  has_one :background_image, class_name: 'Image', uri: nil
6
- has_one :alternate, class_name: 'Recipe', uri: '/recipes/:recipe_id/alternates/recipe'
6
+ has_one :alternate, class_name: 'Recipe', uri: 'recipes/:recipe_id/alternates/recipe'
7
7
  belongs_to :user
8
8
 
9
9
  scope :published, -> { where(status: 'published') }
10
10
  scope :approved, -> { where(approved: true) }
11
- attributes :title
11
+ attributes :title, :description
12
12
 
13
13
  before_save :before_save_callback
14
14
  before_create :before_create_callback
@@ -22,6 +22,10 @@ class Recipe < Spyke::Base
22
22
  result
23
23
  end
24
24
 
25
+ def description
26
+ super
27
+ end
28
+
25
29
  def ingredients
26
30
  groups.flat_map(&:ingredients)
27
31
  end
@@ -35,14 +39,16 @@ end
35
39
 
36
40
  class Image < Spyke::Base
37
41
  method_for :create, :put
42
+ attributes :description, :caption
38
43
  end
39
44
 
40
45
  class StepImage < Image
41
46
  include_root_in_json 'step_image_root'
47
+ attributes :note
42
48
  end
43
49
 
44
50
  class RecipeImage < Image
45
- uri '/recipes/:recipe_id/image'
51
+ uri 'recipes/:recipe_id/image'
46
52
  validates :url, presence: true
47
53
  attributes :url
48
54
 
@@ -62,7 +68,7 @@ class Group < Spyke::Base
62
68
  end
63
69
 
64
70
  class Ingredient < Spyke::Base
65
- uri '/recipes/:recipe_id/ingredients/(:id)'
71
+ uri 'recipes/:recipe_id/ingredients/(:id)'
66
72
  end
67
73
 
68
74
  class User < Spyke::Base
@@ -70,7 +76,7 @@ class User < Spyke::Base
70
76
  end
71
77
 
72
78
  class Photo < Spyke::Base
73
- uri '/images/photos/(:id)'
79
+ uri 'images/photos/(:id)'
74
80
  end
75
81
 
76
82
  class Comment < Spyke::Base
@@ -93,8 +99,8 @@ end
93
99
 
94
100
  module Cookbook
95
101
  class Tip < Spyke::Base
96
- uri '/tips/(:id)'
97
- has_many :likes, class_name: 'Cookbook::Like', uri: '/tips/:cookbook_tip_id/likes/(:id)'
102
+ uri 'tips/(:id)'
103
+ has_many :likes, class_name: 'Cookbook::Like', uri: 'tips/:cookbook_tip_id/likes/(:id)'
98
104
  has_many :favorites
99
105
  has_many :votes
100
106
  has_many :photos, class_name: 'Photo'
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: 1.8.9
4
+ version: 1.8.10
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-02-24 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport