serializer 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,11 +6,12 @@ Serializer is a Ruby on Rails tool for adding accessor to serialized attributes
6
6
 
7
7
  The gem is tested with:
8
8
 
9
- * Ruby (MRI) 1.9.3 (p0)
10
- * Ruby (MRI) 1.9.2 (p180)
11
- * Ruby (MRI) 1.8.7 (p334)
12
- * Ruby (REE) 1.8.7 (2011.03)
13
- * JRuby 1.6.2
9
+ * Ruby (MRI) 2.0.0
10
+ * Ruby (MRI) 1.9.3
11
+ * Ruby (MRI) 1.9.2
12
+ * Ruby (MRI) 1.8.7
13
+ * Ruby (REE) 1.8.7
14
+ * JRuby 1.7.2
14
15
  * Rubinius 1.2.4
15
16
 
16
17
  == Installation
@@ -78,6 +78,7 @@ module Serializer
78
78
  end
79
79
  end
80
80
 
81
+ attribute_will_change!(name)
81
82
  send(name)[method.to_sym] = value
82
83
  end
83
84
 
@@ -1,3 +1,3 @@
1
1
  module Serializer
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,5 @@
1
+ class Subscription < ActiveRecord::Base
2
+ belongs_to :user
3
+
4
+ accepts_nested_attributes_for :user
5
+ end
@@ -1,6 +1,7 @@
1
1
  class User < ActiveRecord::Base
2
2
 
3
3
  belongs_to :account
4
+ has_one :subscription
4
5
 
5
6
  has_serialized :settings do |settings|
6
7
  settings.define :tw_share, :default => true, :type => :boolean
@@ -15,6 +16,9 @@ class User < ActiveRecord::Base
15
16
  settings.define :permissions, :default => [], :type => :array
16
17
 
17
18
  settings.define :mystery
19
+
20
+ settings.define :notifications, :type => :boolean, :default => false
18
21
  end
22
+
19
23
 
20
24
  end
@@ -0,0 +1,9 @@
1
+ class CreateSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :subscriptions do |t|
4
+ t.references :user
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120731074843) do
14
+ ActiveRecord::Schema.define(:version => 20130207030140) do
15
15
 
16
16
  create_table "accounts", :force => true do |t|
17
17
  t.string "name"
@@ -19,6 +19,12 @@ ActiveRecord::Schema.define(:version => 20120731074843) do
19
19
  t.datetime "updated_at", :null => false
20
20
  end
21
21
 
22
+ create_table "subscriptions", :force => true do |t|
23
+ t.integer "user_id"
24
+ t.datetime "created_at", :null => false
25
+ t.datetime "updated_at", :null => false
26
+ end
27
+
22
28
  create_table "users", :force => true do |t|
23
29
  t.integer "account_id"
24
30
  t.string "name"
@@ -4,7 +4,7 @@ class AccountTest < ActiveSupport::TestCase
4
4
 
5
5
  fixtures :all
6
6
 
7
- test "accepts nested attributes for users" do
7
+ test "accepts nested attributes for users on create" do
8
8
  @account = Account.create({ :user_attributes => { :tw_share => false, :fb_share => false, :tb_share => true } })
9
9
  @user = @account.user
10
10
 
@@ -14,4 +14,15 @@ class AccountTest < ActiveSupport::TestCase
14
14
  assert @user.tb_share?, "should have accepted nested attributes"
15
15
  end
16
16
 
17
+ test "accepts nested attributes for users on update" do
18
+ @account = Account.create()
19
+ @account.create_user()
20
+
21
+ @account.update_attributes({ :user_attributes => { :tw_share => true, :fb_share => false, :tb_share => true } })
22
+
23
+ assert !@account.user.fb_share?, "should have accepted nested attributes"
24
+ assert @account.user.tw_share?, "should have accepted nested attributes"
25
+ assert @account.user.tb_share?, "should have accepted nested attributes"
26
+ end
27
+
17
28
  end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class SubscriptionTest < ActiveSupport::TestCase
4
+
5
+ test "accepts nested attributes from belongs_to side of association" do
6
+ @user = User.create()
7
+ @subscription = @user.create_subscription()
8
+
9
+ user_id = @user.id.to_s
10
+
11
+ @subscription.update_attributes({ "user_attributes" => { "notifications" => "1", "id" => user_id } })
12
+ @user.reload
13
+
14
+ assert @user.subscription, "should have an subscription"
15
+ assert @user.notifications?, "should have accepted nested attributes setting to true"
16
+
17
+ @subscription.update_attributes({ "user_attributes" => { "notifications" => "0", "id" => user_id } })
18
+ @user.reload
19
+
20
+ assert !@user.notifications?, "should have accepted nested attributes setting to false"
21
+ end
22
+
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -72,6 +72,7 @@ files:
72
72
  - test/dummy/app/helpers/main_helper.rb
73
73
  - test/dummy/app/helpers/users_helper.rb
74
74
  - test/dummy/app/models/account.rb
75
+ - test/dummy/app/models/subscription.rb
75
76
  - test/dummy/app/models/user.rb
76
77
  - test/dummy/app/views/layouts/application.html.haml
77
78
  - test/dummy/app/views/main/index.html.haml
@@ -96,6 +97,7 @@ files:
96
97
  - test/dummy/db/development.sqlite3
97
98
  - test/dummy/db/migrate/20110927222742_create_users.rb
98
99
  - test/dummy/db/migrate/20120731074843_create_accounts.rb
100
+ - test/dummy/db/migrate/20130207030140_create_subscriptions.rb
99
101
  - test/dummy/db/production.sqlite3
100
102
  - test/dummy/db/schema.rb
101
103
  - test/dummy/db/test.sqlite3
@@ -113,6 +115,7 @@ files:
113
115
  - test/dummy/test/unit/account_test.rb
114
116
  - test/dummy/test/unit/helpers/main_helper_test.rb
115
117
  - test/dummy/test/unit/helpers/users_helper_test.rb
118
+ - test/dummy/test/unit/subscription_test.rb
116
119
  - test/dummy/test/unit/user_test.rb
117
120
  - test/dummy/tmp/cache/assets/C36/B50/sprockets%2F5e8353089687a8324957248c12a6ea87
118
121
  - test/dummy/tmp/cache/assets/C63/7C0/sprockets%2F951340282b11ba35a865d4e04300b3a8
@@ -183,6 +186,7 @@ test_files:
183
186
  - test/dummy/app/helpers/main_helper.rb
184
187
  - test/dummy/app/helpers/users_helper.rb
185
188
  - test/dummy/app/models/account.rb
189
+ - test/dummy/app/models/subscription.rb
186
190
  - test/dummy/app/models/user.rb
187
191
  - test/dummy/app/views/layouts/application.html.haml
188
192
  - test/dummy/app/views/main/index.html.haml
@@ -207,6 +211,7 @@ test_files:
207
211
  - test/dummy/db/development.sqlite3
208
212
  - test/dummy/db/migrate/20110927222742_create_users.rb
209
213
  - test/dummy/db/migrate/20120731074843_create_accounts.rb
214
+ - test/dummy/db/migrate/20130207030140_create_subscriptions.rb
210
215
  - test/dummy/db/production.sqlite3
211
216
  - test/dummy/db/schema.rb
212
217
  - test/dummy/db/test.sqlite3
@@ -224,6 +229,7 @@ test_files:
224
229
  - test/dummy/test/unit/account_test.rb
225
230
  - test/dummy/test/unit/helpers/main_helper_test.rb
226
231
  - test/dummy/test/unit/helpers/users_helper_test.rb
232
+ - test/dummy/test/unit/subscription_test.rb
227
233
  - test/dummy/test/unit/user_test.rb
228
234
  - test/dummy/tmp/cache/assets/C36/B50/sprockets%2F5e8353089687a8324957248c12a6ea87
229
235
  - test/dummy/tmp/cache/assets/C63/7C0/sprockets%2F951340282b11ba35a865d4e04300b3a8