her 0.7.4 → 0.7.5

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: c00165db5b5d258d664ab7dffad4fda96fa46632
4
- data.tar.gz: c44e14e767f426d53cc324a17231f2d43a69eed4
3
+ metadata.gz: 18b4493b9a94d75fb08c9df34781081f9c23af85
4
+ data.tar.gz: d5fd8f8dc913f127c274be1902103f592574049d
5
5
  SHA512:
6
- metadata.gz: b5e658e48405aa84f6c7ca27dd35e4ede6e207d4ac251cd53a6cb7950c94fc59bf924c631c8068d96ab55a37adb4b7a118bba4a11831d84d4f037511965e3d68
7
- data.tar.gz: 966310b9e4d9b99c36d25101c7668af2276d8a806d04b00be0a0b952ab52e579618f4e3750f234da92c5e14f3ea988fde431a9d2d215d0771cb6f3a45baaa956
6
+ metadata.gz: d824a80974f8ab9b67d35e41473ad5f034fbd6756e007a03b407906865de41dd9dfe76273910affcb6bec4926ad38ad846915e489225a11cdc569919659ccd31
7
+ data.tar.gz: 86425b035982382401b6ecec423402760d40cbbbb238eb04673b796d9c73676b12f4b65bf64215e391f2c551ccc03da7005b0ad30ee9d33a871b74eebe7f0bf1
data/.travis.yml CHANGED
@@ -3,6 +3,8 @@ language: ruby
3
3
  sudo: false
4
4
 
5
5
  rvm:
6
+ - 2.2.2
7
+ - 2.1.6
6
8
  - 2.0.0
7
9
  - 1.9.3
8
10
 
data/README.md CHANGED
@@ -757,7 +757,7 @@ Just like with ActiveRecord, you can define named scopes for your models. Scopes
757
757
  class User
758
758
  include Her::Model
759
759
 
760
- scope :by_role, -> { |role| where(role: role) }
760
+ scope :by_role, ->(role) { where(role: role) }
761
761
  scope :admins, -> { by_role('admin') }
762
762
  scope :active, -> { where(active: 1) }
763
763
  end
@@ -779,7 +779,7 @@ class User
779
779
  include Her::Model
780
780
 
781
781
  collection_path "organizations/:organization_id/users"
782
- scope :for_organization, -> { |id| where(organization_id: id) }
782
+ scope :for_organization, ->(id) { where(organization_id: id) }
783
783
  end
784
784
 
785
785
  @user = User.for_organization(3).find(2)
data/lib/her/api.rb CHANGED
@@ -10,8 +10,7 @@ module Her
10
10
 
11
11
  # Setup a default API connection. Accepted arguments and options are the same as {API#setup}.
12
12
  def self.setup(opts={}, &block)
13
- @default_api = new
14
- @default_api.setup(opts, &block)
13
+ @default_api = new(opts, &block)
15
14
  end
16
15
 
17
16
  # Create a new API object. This is useful to create multiple APIs and use them with the `uses_api` method.
@@ -27,14 +26,14 @@ module Her
27
26
  # uses_api api
28
27
  # end
29
28
  def initialize(*args, &blk)
30
- self.setup(*args, &blk)
29
+ setup(*args, &blk)
31
30
  end
32
31
 
33
32
  # Setup the API connection.
34
33
  #
35
34
  # @param [Hash] opts the Faraday options
36
35
  # @option opts [String] :url The main HTTP API root (eg. `https://api.example.com`)
37
- # @option opts [String] :ssl A hash containing [SSL options](https://github.com/technoweenie/faraday/wiki/Setting-up-SSL-certificates)
36
+ # @option opts [String] :ssl A hash containing [SSL options](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates)
38
37
  #
39
38
  # @return Faraday::Connection
40
39
  #
@@ -8,7 +8,7 @@ module Her
8
8
  names.each do |name|
9
9
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
10
10
  def #{name}(*args, &block)
11
- #{target_name}.#{name}(*args, &block)
11
+ #{target_name}.send(#{name.inspect}, *args, &block)
12
12
  end
13
13
  RUBY
14
14
  end
@@ -187,17 +187,15 @@ module Her
187
187
  define_attribute_methods attributes
188
188
 
189
189
  attributes.each do |attribute|
190
- attribute = attribute.to_sym
191
-
192
- unless instance_methods.include?(:"#{attribute}=")
190
+ unless method_defined?(:"#{attribute}=")
193
191
  define_method("#{attribute}=") do |value|
194
192
  @attributes[:"#{attribute}"] = nil unless @attributes.include?(:"#{attribute}")
195
- self.send(:"#{attribute}_will_change!") if @attributes[:'#{attribute}'] != value
193
+ self.send(:"#{attribute}_will_change!") if @attributes[:"#{attribute}"] != value
196
194
  @attributes[:"#{attribute}"] = value
197
195
  end
198
196
  end
199
197
 
200
- unless instance_methods.include?(:"#{attribute}?")
198
+ unless method_defined?(:"#{attribute}?")
201
199
  define_method("#{attribute}?") do
202
200
  @attributes.include?(:"#{attribute}") && @attributes[:"#{attribute}"].present?
203
201
  end
data/lib/her/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Her
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Her::Model::Associations::AssociationProxy do
5
+ describe "proxy assignment methods" do
6
+ before do
7
+ Her::API.setup url: "https://api.example.com" do |builder|
8
+ builder.use Her::Middleware::FirstLevelParseJSON
9
+ builder.use Faraday::Request::UrlEncoded
10
+ builder.adapter :test do |stub|
11
+ stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke" }.to_json ] }
12
+ stub.get("/users/1/fish") { |env| [200, {}, { :id => 1, :name => "Tobias's Fish" }.to_json ] }
13
+ end
14
+ end
15
+ spawn_model "User" do
16
+ has_one :fish
17
+ end
18
+ spawn_model "Fish"
19
+ end
20
+
21
+ subject { User.find(1) }
22
+
23
+ it "should assign value" do
24
+ subject.fish.name = "Fishy"
25
+ expect(subject.fish.name).to eq "Fishy"
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+
@@ -265,4 +265,39 @@ describe Her::Model::Attributes do
265
265
  end
266
266
  end
267
267
  end
268
+
269
+ context "attributes class method" do
270
+ before do
271
+ spawn_model 'Foo::User' do
272
+ attributes :fullname, :document
273
+ end
274
+ end
275
+
276
+ context "instance" do
277
+ subject { Foo::User.new }
278
+
279
+ it { should respond_to(:fullname) }
280
+ it { should respond_to(:fullname=) }
281
+ it { should respond_to(:fullname?) }
282
+ end
283
+
284
+ it "defines setter that affects @attributes" do
285
+ user = Foo::User.new
286
+ user.fullname = 'Tobias Fünke'
287
+ user.attributes[:fullname].should eq('Tobias Fünke')
288
+ end
289
+
290
+ it "defines getter that reads @attributes" do
291
+ user = Foo::User.new
292
+ user.assign_attributes(fullname: 'Tobias Fünke')
293
+ user.fullname.should eq('Tobias Fünke')
294
+ end
295
+
296
+ it "defines predicate that reads @attributes" do
297
+ user = Foo::User.new
298
+ user.fullname?.should be_falsey
299
+ user.assign_attributes(fullname: 'Tobias Fünke')
300
+ user.fullname?.should be_truthy
301
+ end
302
+ end
268
303
  end
@@ -41,6 +41,11 @@ describe "Her::Model and ActiveModel::Dirty" do
41
41
  user.should_not be_changed
42
42
  end
43
43
 
44
+ it "tracks only changed dirty attributes" do
45
+ user.fullname = user.fullname
46
+ user.fullname_changed?.should be_falsey
47
+ end
48
+
44
49
  it "tracks previous changes" do
45
50
  user.fullname = "Tobias Fünke"
46
51
  user.save
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: her
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -208,6 +208,7 @@ files:
208
208
  - spec/middleware/accept_json_spec.rb
209
209
  - spec/middleware/first_level_parse_json_spec.rb
210
210
  - spec/middleware/second_level_parse_json_spec.rb
211
+ - spec/model/associations/association_proxy_spec.rb
211
212
  - spec/model/associations_spec.rb
212
213
  - spec/model/attributes_spec.rb
213
214
  - spec/model/callbacks_spec.rb
@@ -247,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
248
  version: '0'
248
249
  requirements: []
249
250
  rubyforge_project:
250
- rubygems_version: 2.2.2
251
+ rubygems_version: 2.2.3
251
252
  signing_key:
252
253
  specification_version: 4
253
254
  summary: A simple Representational State Transfer-based Hypertext Transfer Protocol-powered
@@ -258,6 +259,7 @@ test_files:
258
259
  - spec/middleware/accept_json_spec.rb
259
260
  - spec/middleware/first_level_parse_json_spec.rb
260
261
  - spec/middleware/second_level_parse_json_spec.rb
262
+ - spec/model/associations/association_proxy_spec.rb
261
263
  - spec/model/associations_spec.rb
262
264
  - spec/model/attributes_spec.rb
263
265
  - spec/model/callbacks_spec.rb