toast 0.8.5 → 0.8.6

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.
@@ -17,7 +17,6 @@ class ToastController < ApplicationController
17
17
  return head(:not_found)
18
18
 
19
19
  rescue Toast::PayloadInvalid => e
20
- raise e if Rails.env == "test"
21
20
  return render :text => e.message, :status => :forbidden
22
21
 
23
22
  rescue Toast::PayloadFormatError => e
@@ -88,15 +88,10 @@ module Toast
88
88
  raise PayloadFormatError
89
89
  end
90
90
 
91
- # ignore:
92
- # * all exposed readable, but not writable fields
93
- # * all associations
94
- # * self
95
- ((@associate_config_in.readables - @associate_config_in.writables) +
96
- @associate_config_in.exposed_associations + ["self"]).each do |rof|
97
- payload.delete(rof)
98
- end
99
-
91
+ payload.delete_if {|key,value|
92
+ !@associate_config_in.writables.include?(key) or
93
+ @associate_config_in.exposed_associations.include?(key)
94
+ }
100
95
 
101
96
  begin
102
97
  reflection = @model.reflect_on_association(@assoc.to_sym)
@@ -91,11 +91,10 @@ module Toast
91
91
  raise PayloadFormatError
92
92
  end
93
93
 
94
- # silently ignore all exposed readable, but not writable fields
95
- ((@config_in.readables - @config_in.writables) + @config_in.exposed_associations + ["self"]).each do |rof|
96
- payload.delete(rof)
97
- end
98
-
94
+ payload.delete_if {|key,value|
95
+ !@config_in.writables.include?(key) or
96
+ @config_in.exposed_associations.include?(key)
97
+ }
99
98
 
100
99
  begin
101
100
 
data/lib/toast/record.rb CHANGED
@@ -34,13 +34,11 @@ module Toast
34
34
  raise PayloadFormatError
35
35
  end
36
36
 
37
- # ignore:
38
- # * all exposed readable, but not writable fields
39
- # * all associations
40
- # * self
41
- ((@config_in.readables - @config_in.writables) + @config_in.exposed_associations + ["self"]).each do |rof|
42
- payload.delete(rof)
43
- end
37
+ # ignore all not explicitly writable attribute
38
+ payload.delete_if {|key,value|
39
+ !@config_in.writables.include?(key) or
40
+ @config_in.exposed_associations.include?(key)
41
+ }
44
42
 
45
43
  # set the virtual attributes
46
44
  (@config_in.writables - @record.attribute_names - @config_in.exposed_associations).each do |vattr|
@@ -53,7 +51,7 @@ module Toast
53
51
  end
54
52
 
55
53
  # mass-update for the rest
56
- @record.update_attributes payload
54
+ @record.update_attributes! payload
57
55
  {
58
56
  :json => @record.represent( @config_out.exposed_attributes,
59
57
  @config_out.exposed_associations,
@@ -63,6 +61,10 @@ module Toast
63
61
  :location => self.base_uri + @record.uri_path,
64
62
  :content_type => @config_out.media_type
65
63
  }
64
+
65
+ rescue ActiveRecord::RecordInvalid => e
66
+ # model validation failed
67
+ raise PayloadInvalid.new(e.message)
66
68
  end
67
69
 
68
70
  def get
data/lib/toast/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toast
2
- VERSION = '0.8.5'
2
+ VERSION = '0.8.6'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toast
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 5
10
- version: 0.8.5
9
+ - 6
10
+ version: 0.8.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "robokopp (Robert Anni\xC3\xA9s)"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-20 00:00:00 Z
18
+ date: 2012-09-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails