daylight 0.9.0.rc3 → 0.9.0

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: bb3cda8546b99d74c72bf1af1ca14aabb51f3d8d
4
- data.tar.gz: 41ad2d678d9aa293cc766179e2441789b7b351be
3
+ metadata.gz: 08c46be1b29ddf3b0176ce3f19ba748e66a46367
4
+ data.tar.gz: cea49a78f45211d2ae637a92ba4820162034c61f
5
5
  SHA512:
6
- metadata.gz: 75780f4b059adb79463f13b0b41e01ae105ecdcad262ca59f133d4624c0fe5557bcc927f9f8a341961d6be8bba5a1720fbd70af0e749202ee8d2aca704b95a99
7
- data.tar.gz: 438f45ccd0e69581e5c2217d989bfe0b9fa238c8665d184632a76cd9055c6a83cb3df5257c7376c4a968b1904b5e61685f2dc2eb38ac7f97776437222f16edbd
6
+ metadata.gz: 4a5dd76c1cade7512e2f9088118de7d8f046fdb7913bdc5d51efa4335b032d11221ec59df4997d18534a7358ff827a6aee6b9a9a2743ff7b16241398515ad31b
7
+ data.tar.gz: a88a975def4fc132cb904b17fd06db5075afac5e51109807e673ddd43c028087ce3606cb107a51c29138d9db7a5788f339dfcc4af5e7cecda04a4c860900f680
data/doc/usage.md CHANGED
@@ -500,13 +500,18 @@ The same is true of nested objects in collections:
500
500
 
501
501
  ````ruby
502
502
  post = API::Post.first
503
- post.comments.first.message = "First!"
503
+ post.comments[0].message = "First!"
504
504
  post.save #=> true
505
505
 
506
506
  post = API::Post.first
507
- post.comments.first.message #=> "First!"
507
+ post.comments[0].message #=> "First!"
508
508
  ````
509
509
 
510
+ > NOTE: In the previous example the following will NOT work:
511
+ > `post.comments.first.message = "First!"`
512
+ > The collection isn't loaded when you use `first`, so Daylight cannot
513
+ > save any changes to the collection.
514
+
510
515
  #### Associating an Existing Nested Resources
511
516
 
512
517
  Associating using an existing nested records is possible with Daylight. The
@@ -557,6 +562,7 @@ A collection can also be reset:
557
562
  post = API::Post.first
558
563
  post.comments.count #=> 4
559
564
  post.comments = []
565
+
560
566
  post.save #=> true
561
567
 
562
568
  post = API::Post.first
@@ -3,7 +3,7 @@ module Daylight
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
5
  PATCH = 0
6
- BUILD = 'rc3'
6
+ BUILD = nil
7
7
 
8
8
  Daylight::VERSION = STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
9
  end
@@ -206,6 +206,7 @@ class Daylight::APIController < ApplicationController
206
206
  # This has become necessary as of Rails 4.0.9 and 4.1.5 because of this security fix:
207
207
  # https://groups.google.com/forum/#!topic/rubyonrails-security/M4chq5Sb540
208
208
  def where_params
209
+ return params unless params.respond_to? :permit
209
210
  params.permit(*ALLOWED_WHERE_PARAMS,
210
211
  filters: params[:filters].try(:keys),
211
212
  scopes: [])
@@ -4,6 +4,7 @@
4
4
  require 'extensions/array_ext' # non-destructive version of `extract_options`
5
5
  require 'extensions/inflections' # custom inflections for the ActiveSupport::Inflector
6
6
  require 'extensions/autosave_association_fix' # fix for autosaving `inverse_of` associations
7
+ require 'extensions/deep_munge_fix' # fix to maintain empty arrays in deep_munge
7
8
  require 'extensions/has_one_serializer_ext' # serializer recognizes belong_to :through association
8
9
  require 'extensions/nested_attributes_ext' # associates two previously existing records
9
10
  require 'extensions/read_only_attributes' # serializer support for `read_only` attributes
@@ -0,0 +1,39 @@
1
+ # Rails' deep_munge nukes empty arrays out of params.
2
+ # Here we are allowing it so we can properly reset associations.
3
+ #
4
+ # see https://github.com/rails/rails/pull/11044
5
+ # and https://github.com/rails/rails/issues/13420
6
+
7
+ module DeepMungeFix
8
+ def deep_munge(hash)
9
+ hash.each do |k, v|
10
+ case v
11
+ when Array
12
+ v.grep(Hash) { |x| deep_munge(x) }
13
+ if v.empty?
14
+ hash[k] = []
15
+ else
16
+ v.compact!
17
+ hash[k] = nil if v.empty?
18
+ end
19
+ when Hash
20
+ deep_munge(v)
21
+ end
22
+ end
23
+ hash
24
+ end
25
+ end
26
+
27
+ ActionDispatch::Request.class_eval do
28
+ if self.const_defined? :Utils
29
+ # for Rails 4.1
30
+ self::Utils.class_eval do
31
+ class << self
32
+ prepend DeepMungeFix
33
+ end
34
+ end
35
+ else
36
+ # for Rails 4.0
37
+ prepend DeepMungeFix
38
+ end
39
+ end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class Suite < ActiveRecord::Base
4
+ scope :all_suites, -> { all }
4
5
  has_many :cases
5
6
 
6
7
  def odd_cases
@@ -88,7 +89,7 @@ describe Daylight::APIController, type: :controller do
88
89
  describe "rescues errors" do
89
90
  # rspec-rails does not honor the tests(controller) function
90
91
  def self.controller_class
91
- TestErrorsController
92
+ TestErrorsController
92
93
  end
93
94
 
94
95
  before do
@@ -318,11 +319,8 @@ describe Daylight::APIController, type: :controller do
318
319
  let!(:suite2) { create(:suite, switch: false) }
319
320
  let!(:suite3) { create(:suite, switch: true) }
320
321
 
321
- def parse_collection body, root='anonymous'
322
- JSON.parse(body).values.first.
323
- map(&:values).
324
- map(&:first).
325
- map(&:with_indifferent_access)
322
+ def parse_collection body
323
+ JSON.parse(body).values.first.map(&:with_indifferent_access)
326
324
  end
327
325
 
328
326
  def parse_record body
@@ -416,6 +414,41 @@ describe Daylight::APIController, type: :controller do
416
414
  ids.should be_include(odd_case_ids.first)
417
415
  ids.should be_include(odd_case_ids.last)
418
416
  end
417
+
418
+ describe :where_params do
419
+ it 'just returns params if it is not a strong parameter object' do
420
+ controller.stub params: {wibble: 'foo'}
421
+
422
+ get :index
423
+
424
+ assert_response :success
425
+ end
426
+
427
+ it 'only allow allowed where params' do
428
+ get :index, limit: 3
429
+
430
+ assert_response :success
431
+ end
432
+
433
+ it 'allows filters' do
434
+ get :index, filters: {name: 'bar'}
435
+
436
+ assert_response :success
437
+ end
438
+
439
+ it 'allows any scopes' do
440
+ get :index, scopes: ['all_suites']
441
+
442
+ assert_response :success
443
+ end
444
+
445
+ it 'knocks back bad params' do
446
+ get :index, an_unpermitted_param: 'foo'
447
+
448
+ assert_response :unprocessable_entity
449
+ JSON.parse(response.body)['errors']['an_unpermitted_param'].should == ['unpermitted parameter']
450
+ end
451
+ end
419
452
  end
420
453
 
421
454
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.rc3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid MacDonald
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-26 00:00:00.000000000 Z
12
+ date: 2014-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: 0.8.1
76
+ version: 0.8.2
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ~>
82
82
  - !ruby/object:Gem::Version
83
- version: 0.8.1
83
+ version: 0.8.2
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rspec
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -245,6 +245,7 @@ files:
245
245
  - rails/daylight/tasks.rb
246
246
  - rails/extensions/array_ext.rb
247
247
  - rails/extensions/autosave_association_fix.rb
248
+ - rails/extensions/deep_munge_fix.rb
248
249
  - rails/extensions/has_one_serializer_ext.rb
249
250
  - rails/extensions/inflections.rb
250
251
  - rails/extensions/nested_attributes_ext.rb
@@ -345,9 +346,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
345
346
  version: '0'
346
347
  required_rubygems_version: !ruby/object:Gem::Requirement
347
348
  requirements:
348
- - - '>'
349
+ - - '>='
349
350
  - !ruby/object:Gem::Version
350
- version: 1.3.1
351
+ version: '0'
351
352
  requirements: []
352
353
  rubyforge_project:
353
354
  rubygems_version: 2.0.3