dm_preferences 1.0 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NGU0NzUwOWQ4MGQ2ZGZmZWM4OWNmNjAwNmNmZjU1MmEyMmVkYzkxZA==
5
- data.tar.gz: !binary |-
6
- MzE1ZGI3ZDU1MWE4MDI5MmI5ZmY1YTFlM2I2MDkxZTQzYmVlNTdjOQ==
2
+ SHA1:
3
+ metadata.gz: 49d213a6e7ac0f8c5ba3a6f8e6e4632d6464e6be
4
+ data.tar.gz: 59c090fd0fbbbcec663186af3b6f247bdcd659f9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZmFlY2JjODc2NDViNGVkMmY0MmNiNzQwMGRhNDkyZmY3NGFhZjllZjU5OTk1
10
- YmRlNTMzZTQ5YzJkNTZiZDVkNzNkMWY5ZGJkZDY1ODBkNjM2MTdmZGNkNjcw
11
- NTE1NjEzOWJiYjM5Yjk3MmM4ZmIzOTM0MjJiZWNhNGE0NGIyYzQ=
12
- data.tar.gz: !binary |-
13
- MmVlNjc1MTk5NDE0Mzg0MDZiZDJjYmRjMTM1ZjNmMjU5MTY0NzA2MzliMjc4
14
- OWJkNTk1OTQ4Y2VkMzkzODc3YjY1MzM1ZTIxMzJiN2YxMjIwNWU1ZDRlYzBk
15
- ZDc3YjZhYTBjMWJlN2NiNGQ4OWFiMjM4ODE2ZDY3NjdkYTA4ZmM=
6
+ metadata.gz: dc16349648397c51ce37ecfae41f4f58cd9fbf24b387e90f38b253b0810b754f31c20e62670ebc8aa51358b307c6a68fceca0c05fafc056ec31e81da135b84ab
7
+ data.tar.gz: 34d8971768549155dc184c509f21eb24d06c8f013ece976a37f2a8ba1b7386b762420d73aaa7aa8ebaa394166711ce0afc2d1a941bfcd79e5a7e669d0614f72c
data/.gitignore CHANGED
@@ -7,3 +7,5 @@ test/app_root/script
7
7
  Gemfile.lock
8
8
  spec/dummy/db/test.sqlite3
9
9
  spec/dummy/log
10
+ .DS_Store
11
+ .byebug_history
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
+ env:
2
+ - "RAILS_VERSION=4.2.0"
3
+ - "RAILS_VERSION=5.0.0"
4
+
1
5
  rvm:
2
- - 1.9.3
3
- - 2.1
6
+ - 2.2.2
7
+ - 2.3.1
data/Gemfile CHANGED
@@ -1,3 +1,25 @@
1
1
  source "http://www.rubygems.org"
2
2
 
3
+ rails_version = ENV["RAILS_VERSION"] || "default"
4
+
5
+ rails = case rails_version
6
+ when "master"
7
+ {github: "rails/rails"}
8
+ when "default"
9
+ ">= 3.2.0"
10
+ else
11
+ "~> #{rails_version}"
12
+ end
13
+
14
+ gem "rails", rails
15
+
3
16
  gemspec
17
+
18
+ group :development, :test do
19
+ gem 'sqlite3'
20
+ gem 'byebug'
21
+
22
+ gem 'mocha', '~> 1.1.0', :require => false
23
+ gem 'rspec-rails', '~> 3.5.0'
24
+ gem 'factory_girl_rails', '~> 4.4.1'
25
+ end
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  **Preferences** adds support for easily creating custom preferences for models.
7
7
 
8
- This gem is a fork of the original [preferences gem by Aaron Pfeifer](https://github.com/pluginaweek/preferences). It supports Rails 4.2, and all tests are working. The gem has been renamed to [dm_preferences](https://rubygems.org/gems/dm_preferences) so as not to conflict with the original.
8
+ This gem is a fork of the original [preferences gem by Aaron Pfeifer](https://github.com/pluginaweek/preferences). It supports Rails 5 and 4.2, and all tests are working. The gem has been renamed to [dm_preferences](https://rubygems.org/gems/dm_preferences) so as not to conflict with the original.
9
9
 
10
10
  ## Description
11
11
 
@@ -32,7 +32,7 @@ a separate table and making it dead-simple to define and manage preferences.
32
32
 
33
33
  Add the following to your gem file:
34
34
 
35
- gem 'dm_preferences', '~> 1.0'
35
+ gem 'dm_preferences', '~> 1.5'
36
36
 
37
37
  _preferences_ requires an additional database table to work. You can generate
38
38
  a migration for this table like so:
@@ -268,5 +268,6 @@ Mailing List
268
268
 
269
269
  ## Dependencies
270
270
 
271
+ * 1.5.x for Rails 5
271
272
  * 1.0.x for Rails 4.2
272
273
  * 0.5.6 for Rails 4.1
@@ -52,10 +52,11 @@ class Preference < ActiveRecord::Base
52
52
  end
53
53
 
54
54
  # Only searches for the group record if the group id is specified
55
- def group_with_optional_lookup
56
- group_id ? group_without_optional_lookup : group_type
55
+ alias_method :original_group, :group
56
+ def group
57
+ group_id ? original_group : group_type
57
58
  end
58
- alias_method_chain :group, :optional_lookup
59
+
59
60
 
60
61
  private
61
62
  # Finds the definition for this preference in the given owner class.
@@ -17,7 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.rdoc_options = %w(--line-numbers --inline-source --title preferences --main README.rdoc)
18
18
  s.extra_rdoc_files = %w(README.md CHANGELOG.md LICENSE)
19
19
 
20
- s.add_development_dependency "rails", "~> 4.2"
21
- s.add_development_dependency "sqlite3", '~> 0'
22
- s.add_development_dependency 'rspec-rails', '~> 3.0'
20
+ s.add_dependency "rails", ">= 4.2"
23
21
  end
data/lib/preferences.rb CHANGED
@@ -230,7 +230,7 @@ module Preferences
230
230
  # Generates the scope for looking under records with a specific set of
231
231
  # preferences associated with them.
232
232
  #
233
- # Note thate this is a bit more complicated than usual since the preference
233
+ # Note that this is a bit more complicated than usual since the preference
234
234
  # definitions aren't in the database for joins, defaults need to be accounted
235
235
  # for, and querying for the the presence of multiple preferences requires
236
236
  # multiple joins.
@@ -260,7 +260,7 @@ module Preferences
260
260
 
261
261
  # Since each preference is a different record, they need their own
262
262
  # join so that the proper conditions can be set
263
- joins << "LEFT JOIN preferences AS #{table} ON #{table}.owner_id = #{table_name}.#{primary_key} AND " +
263
+ joins << "LEFT JOIN preferences AS #{table} ON #{table}.owner_id = #{table_name}.#{primary_key} AND " +
264
264
  sanitize_sql_hash_for_conditions(
265
265
  "#{table}.owner_type" => base_class.name.to_s,
266
266
  "#{table}.group_id" => group_id,
@@ -280,17 +280,15 @@ module Preferences
280
280
  joins(joins).where(values.unshift(sql))
281
281
  end
282
282
 
283
- # this function is deprecated in 4.2 and to be removed in 5.0.
284
- # but it's useful, particularly how it can handle conditions that are nil.
285
- # so keep it for now.
286
- def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name)
287
- attrs = ActiveRecord::PredicateBuilder.resolve_column_aliases self, attrs
288
- attrs = expand_hash_conditions_for_aggregates(attrs)
289
-
290
- table = Arel::Table.new(table_name, arel_engine).alias(default_table_name)
291
- ActiveRecord::PredicateBuilder.build_from_hash(self, attrs, table).map { |b|
292
- connection.visitor.compile b
293
- }.join(' AND ')
283
+ # The Rails version of this function was removed in 5.0. So use this instead.
284
+ # It properly handles the 'IS NULL' case
285
+ def sanitize_sql_hash_for_conditions(attrs)
286
+ return '' unless attrs.is_a? Hash
287
+ conditions = []
288
+ attrs.each do |key, value|
289
+ conditions << (value ? sanitize_sql_for_conditions(["#{key} = ?", value]) : "#{key} IS NULL")
290
+ end
291
+ conditions.join(' AND ')
294
292
  end
295
293
 
296
294
  end
@@ -3,13 +3,13 @@ module Preferences
3
3
  class PreferenceDefinition
4
4
  # The data type for the content stored in this preference type
5
5
  attr_reader :type
6
-
6
+
7
7
  def initialize(name, *args) #:nodoc:
8
8
  options = args.extract_options!
9
9
  options.assert_valid_keys(:default, :group_defaults)
10
10
 
11
11
  @type = args.first ? args.first.to_sym : :boolean
12
-
12
+
13
13
  case @type
14
14
  when :any
15
15
  @klass = "ActiveRecord::Type::Value".constantize.new
@@ -27,32 +27,38 @@ module Preferences
27
27
  defaults
28
28
  end
29
29
  end
30
-
30
+
31
31
  # The name of the preference
32
32
  def name
33
33
  @column.name
34
34
  end
35
-
35
+
36
36
  # The default value to use for the preference in case none have been
37
37
  # previously defined
38
38
  def default_value(group = nil)
39
39
  @group_defaults.include?(group) ? @group_defaults[group] : type_cast(@column.default)
40
40
  end
41
-
41
+
42
42
  # Determines whether column backing this preference stores numberic values
43
43
  def number?
44
- @column.number?
44
+ @column.type == :integer || @column.type == :float
45
45
  end
46
-
46
+
47
47
  # Typecasts the value based on the type of preference that was defined.
48
48
  # This uses ActiveRecord's typecast functionality so the same rules for
49
49
  # typecasting a model's columns apply here.
50
50
  def type_cast(value)
51
- return 1 if @type == :integer && value == true
52
- return 0 if @type == :integer && value == false
53
- @type == :any ? value : @column.type_cast_from_database(value)
51
+ return 1 if @type == :integer && value == true
52
+ return 0 if @type == :integer && value == false
53
+ return true if @type == :boolean && (value == 't' || value == true)
54
+ return false if @type == :boolean && (value == 'f' || value == false)
55
+ if @type == :any
56
+ value
57
+ else
58
+ @klass.respond_to?(:deserialize) ? @klass.deserialize(value) : @column.type_cast_from_database(value)
59
+ end
54
60
  end
55
-
61
+
56
62
  # Typecasts the value to true/false depending on the type of preference
57
63
  def query(value)
58
64
  if !(value = type_cast(value))
@@ -1,3 +1,3 @@
1
1
  module Preferences
2
- VERSION = '1.0'
2
+ VERSION = '1.5'
3
3
  end
@@ -1,8 +1,8 @@
1
1
  class User < ActiveRecord::Base
2
- # preference :hot_salsa
3
- # preference :dark_chocolate, :default => true
4
- # preference :color, :string
5
- # preference :car, :integer
6
- # preference :language, :string, :default => 'English'
7
- # preference :data, :any
2
+ preference :hot_salsa
3
+ preference :dark_chocolate, :default => true
4
+ preference :color, :string
5
+ preference :car, :integer
6
+ preference :language, :string, :default => 'English'
7
+ preference :data, :any
8
8
  end
@@ -24,9 +24,6 @@ module Dummy
24
24
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
25
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
26
  # config.i18n.default_locale = :de
27
-
28
- # Do not swallow errors in after_commit/after_rollback callbacks.
29
- config.active_record.raise_in_transactional_callbacks = true
30
27
  end
31
28
  end
32
29
 
@@ -13,8 +13,8 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static file server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
16
+ # config.public_file_server.enabled = true
17
+ # config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
18
18
 
19
19
  # Show full error reports and disable caching.
20
20
  config.consider_all_requests_local = true
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -31,10 +30,9 @@ ActiveRecord::Schema.define(version: 4) do
31
30
  t.string "value"
32
31
  t.datetime "created_at"
33
32
  t.datetime "updated_at"
33
+ t.index ["owner_id", "owner_type", "name", "group_id", "group_type"], name: "index_preferences_on_owner_and_name_and_preference", unique: true
34
34
  end
35
35
 
36
- add_index "preferences", ["owner_id", "owner_type", "name", "group_id", "group_type"], name: "index_preferences_on_owner_and_name_and_preference", unique: true
37
-
38
36
  create_table "users", force: :cascade do |t|
39
37
  t.string "login", null: false
40
38
  end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :car do
3
+ name 'Porsche'
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :employee do
3
+ name 'John Smith'
4
+
5
+ trait :manager do
6
+ end
7
+ end
8
+
9
+ factory :manager, parent: :employee, class: 'Manager' do
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :preference do
3
+ name 'notifications'
4
+ value false
5
+ association :owner, factory: :user
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ login 'admin'
4
+ end
5
+ end
@@ -1,23 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "ModelPreferenceTest" do
4
- after do
4
+ after :each do
5
5
  User.preference_definitions.clear
6
6
  end
7
7
 
8
8
  #------------------------------------------------------------------------------
9
9
  describe "ModelWithoutPreferencesTest" do
10
10
  it "test_should_not_create_preference_definitions" do
11
- assert !Car.respond_to?(:preference_definitions)
11
+ expect(!Car.respond_to?(:preference_definitions)).to eq true
12
12
  end
13
13
 
14
14
  it "test_should_not_create_stored_preferences_association" do
15
- assert !Car.new.respond_to?(:stored_preferences)
15
+ expect(!Car.new.respond_to?(:stored_preferences)).to eq true
16
16
  end
17
17
 
18
18
  it "test_should_not_create_preference_scopes" do
19
- assert !Car.respond_to?(:with_preferences)
20
- assert !Car.respond_to?(:without_preferences)
19
+ expect(!Car.respond_to?(:with_preferences)).to eq true
20
+ expect(!Car.respond_to?(:without_preferences)).to eq true
21
21
  end
22
22
  end
23
23
 
@@ -25,20 +25,20 @@ describe "ModelPreferenceTest" do
25
25
  describe "PreferencesAfterFirstBeingDefinedTest" do
26
26
  before do
27
27
  User.preference :notifications
28
- @user = new_user
28
+ @user = build(:user)
29
29
  end
30
30
 
31
31
  it "test_should_create_preference_definitions" do
32
- assert User.respond_to?(:preference_definitions)
32
+ expect(User.respond_to?(:preference_definitions)).to eq true
33
33
  end
34
34
 
35
35
  it "test_should_create_preference_scopes" do
36
- assert User.respond_to?(:with_preferences)
37
- assert User.respond_to?(:without_preferences)
36
+ expect(User.respond_to?(:with_preferences)).to eq true
37
+ expect(User.respond_to?(:without_preferences)).to eq true
38
38
  end
39
39
 
40
40
  it "test_should_create_stored_preferences_associations" do
41
- assert @user.respond_to?(:stored_preferences)
41
+ expect(@user.respond_to?(:stored_preferences)).to eq true
42
42
  end
43
43
  end
44
44
 
@@ -46,7 +46,7 @@ describe "ModelPreferenceTest" do
46
46
  describe "PreferencesAfterBeingDefinedTest" do
47
47
  before do
48
48
  @definition = User.preference :notifications
49
- @user = new_user
49
+ @user = build(:user)
50
50
  end
51
51
 
52
52
  it "test_should_raise_exception_if_invalid_options_specified" do
@@ -60,75 +60,75 @@ describe "ModelPreferenceTest" do
60
60
 
61
61
  it "test_should_create_definition" do
62
62
  expect(@definition.nil?).to eq false
63
- assert_equal 'notifications', @definition.name
63
+ expect(@definition.name).to eq 'notifications'
64
64
  end
65
65
 
66
66
  it "test_should_create_preferred_query_method" do
67
- assert @user.respond_to?(:preferred_notifications?)
67
+ expect(@user.respond_to?(:preferred_notifications?)).to eq true
68
68
  end
69
69
 
70
70
  it "test_should_create_prefers_query_method" do
71
- assert @user.respond_to?(:prefers_notifications?)
71
+ expect(@user.respond_to?(:prefers_notifications?)).to eq true
72
72
  end
73
73
 
74
74
  it "test_should_create_preferred_reader" do
75
- assert @user.respond_to?(:preferred_notifications)
75
+ expect(@user.respond_to?(:preferred_notifications)).to eq true
76
76
  end
77
77
 
78
78
  it "test_should_create_prefers_reader" do
79
- assert @user.respond_to?(:prefers_notifications)
79
+ expect(@user.respond_to?(:prefers_notifications)).to eq true
80
80
  end
81
81
 
82
82
  it "test_should_create_preferred_writer" do
83
- assert @user.respond_to?(:preferred_notifications=)
83
+ expect(@user.respond_to?(:preferred_notifications=)).to eq true
84
84
  end
85
85
 
86
86
  it "test_should_create_prefers_writer" do
87
- assert @user.respond_to?(:prefers_notifications=)
87
+ expect(@user.respond_to?(:prefers_notifications=)).to eq true
88
88
  end
89
89
 
90
90
  it "test_should_create_preferred_changed_query" do
91
- assert @user.respond_to?(:preferred_notifications_changed?)
91
+ expect(@user.respond_to?(:preferred_notifications_changed?)).to eq true
92
92
  end
93
93
 
94
94
  it "test_should_create_prefers_changed_query" do
95
- assert @user.respond_to?(:prefers_notifications_changed?)
95
+ expect(@user.respond_to?(:prefers_notifications_changed?)).to eq true
96
96
  end
97
97
 
98
98
  it "test_should_create_preferred_was" do
99
- assert @user.respond_to?(:preferred_notifications_was)
99
+ expect(@user.respond_to?(:preferred_notifications_was)).to eq true
100
100
  end
101
101
 
102
102
  it "test_should_create_prefers_was" do
103
- assert @user.respond_to?(:prefers_notifications_was)
103
+ expect(@user.respond_to?(:prefers_notifications_was)).to eq true
104
104
  end
105
105
 
106
106
  it "test_should_create_preferred_change" do
107
- assert @user.respond_to?(:preferred_notifications_change)
107
+ expect(@user.respond_to?(:preferred_notifications_change)).to eq true
108
108
  end
109
109
 
110
110
  it "test_should_create_prefers_change" do
111
- assert @user.respond_to?(:prefers_notifications_change)
111
+ expect(@user.respond_to?(:prefers_notifications_change)).to eq true
112
112
  end
113
113
 
114
114
  it "test_should_create_preferred_will_change" do
115
- assert @user.respond_to?(:preferred_notifications_will_change!)
115
+ expect(@user.respond_to?(:preferred_notifications_will_change!)).to eq true
116
116
  end
117
117
 
118
118
  it "test_should_create_prefers_will_change" do
119
- assert @user.respond_to?(:prefers_notifications_will_change!)
119
+ expect(@user.respond_to?(:prefers_notifications_will_change!)).to eq true
120
120
  end
121
121
 
122
122
  it "test_should_create_preferred_reset" do
123
- assert @user.respond_to?(:reset_preferred_notifications!)
123
+ expect(@user.respond_to?(:reset_preferred_notifications!)).to eq true
124
124
  end
125
125
 
126
126
  it "test_should_create_prefers_reset" do
127
- assert @user.respond_to?(:reset_prefers_notifications!)
127
+ expect(@user.respond_to?(:reset_prefers_notifications!)).to eq true
128
128
  end
129
129
 
130
130
  it "test_should_include_new_definitions_in_preference_definitions" do
131
- assert_equal User.preference_definitions['notifications'], @definition
131
+ expect(@definition).to eq User.preference_definitions['notifications']
132
132
  end
133
133
  end
134
134
 
@@ -136,67 +136,64 @@ describe "ModelPreferenceTest" do
136
136
  describe "PreferencesTypeCasted" do
137
137
  before do
138
138
  @definition = User.preference :rate, :float, :default => 1.0
139
- @user = new_user
139
+ @user = build(:user)
140
140
  end
141
141
 
142
142
  it "test_should_have_float_type" do
143
- assert_equal :float, @definition.type
143
+ expect(@definition.type).to eq :float
144
144
  end
145
145
 
146
146
  it "test_should_only_have_default_preferences" do
147
- assert_equal e = {'rate' => 1.0}, @user.preferences
147
+ expect(@user.preferences).to eq ({'rate' => 1.0})
148
148
  end
149
149
 
150
150
  it "test_should_type_cast_changed_values" do
151
151
  @user.write_preference(:rate, "1.1")
152
- assert_equal e = {'rate' => 1.1}, @user.preferences
152
+ expect(@user.preferences).to eq ({'rate' => 1.1})
153
153
  end
154
154
  end
155
155
 
156
156
  #------------------------------------------------------------------------------
157
157
  describe "PreferencesByDefaultTest" do
158
158
  before do
159
- include Factory
160
-
161
159
  @definition = User.preference :notifications
162
- @user = new_user
160
+ @user = build(:user)
163
161
  end
164
162
 
165
163
  it "test_should_have_boolean_type" do
166
- assert_equal :boolean, @definition.type
164
+ expect(@definition.type).to eq :boolean
167
165
  end
168
166
 
169
167
  it "test_should_not_have_default_value" do
170
- assert_nil @definition.default_value
168
+ expect(@definition.default_value).to eq nil
171
169
  end
172
170
 
173
171
  it "test_should_only_have_default_preferences" do
174
- # assert_equal e = {'notifications' => nil}, @user.preferences
175
- assert_equal e = {'notifications' => nil}, @user.preferences
172
+ expect(@user.preferences).to eq ({'notifications' => nil})
176
173
  end
177
174
 
178
175
  it "test_should_not_query_preferences_changed" do
179
- assert_equal false, @user.preferences_changed?
176
+ expect(@user.preferences_changed?).to eq false
180
177
  end
181
178
 
182
179
  it "test_should_not_query_group_preferences_changed" do
183
- assert_equal false, @user.preferences_changed?(:chat)
180
+ expect(@user.preferences_changed?(:chat)).to eq false
184
181
  end
185
182
 
186
183
  it "test_should_not_have_preferences_changed" do
187
- assert_equal [], @user.preferences_changed
184
+ expect(@user.preferences_changed).to eq []
188
185
  end
189
186
 
190
187
  it "test_should_not_have_group_preferences_changed" do
191
- assert_equal [], @user.preferences_changed(:chat)
188
+ expect(@user.preferences_changed(:chat)).to eq []
192
189
  end
193
190
 
194
191
  it "test_should_not_have_preference_changes" do
195
- assert_equal e = {}, @user.preference_changes
192
+ expect(@user.preference_changes).to eq ({})
196
193
  end
197
194
 
198
195
  it "test_should_not_have_group_preference_changes" do
199
- assert_equal e = {}, @user.preference_changes(:chat)
196
+ expect(@user.preference_changes(:chat)).to eq ({})
200
197
  end
201
198
  end
202
199
 
@@ -204,19 +201,19 @@ describe "ModelPreferenceTest" do
204
201
  describe "PreferencesWithCustomTypeTest" do
205
202
  before do
206
203
  @definition = User.preference :vehicle_id, :integer
207
- @user = new_user
204
+ @user = build(:user)
208
205
  end
209
206
 
210
207
  it "test_should_have_integer_type" do
211
- assert_equal :integer, @definition.type
208
+ expect(@definition.type).to eq :integer
212
209
  end
213
210
 
214
211
  it "test_should_not_have_default_value" do
215
- assert_nil @definition.default_value
212
+ expect(@definition.default_value).to eq nil
216
213
  end
217
214
 
218
215
  it "test_should_only_have_default_preferences" do
219
- assert_equal e = {'vehicle_id' => nil}, @user.preferences
216
+ expect(@user.preferences).to eq ({'vehicle_id' => nil})
220
217
  end
221
218
  end
222
219
 
@@ -224,44 +221,45 @@ describe "ModelPreferenceTest" do
224
221
  describe "PreferencesWithCustomDefaultTest" do
225
222
  before do
226
223
  @definition = User.preference :color, :string, :default => 'red'
227
- @user = new_user
224
+ @user = build(:user)
228
225
  end
229
226
 
230
227
  it "test_should_have_boolean_type" do
231
- assert_equal :string, @definition.type
228
+ expect(@definition.type).to eq :string
232
229
  end
233
230
 
234
231
  it "test_should_have_default_value" do
235
- assert_equal 'red', @definition.default_value
232
+ expect(@definition.default_value).to eq 'red'
236
233
  end
237
234
 
238
235
  it "test_should_only_have_default_preferences" do
239
- assert_equal e = {'color' => 'red'}, @user.preferences
236
+ expect(@user.preferences).to eq ({'color' => 'red'})
240
237
  end
241
238
  end
242
239
 
243
240
  #------------------------------------------------------------------------------
244
241
  describe "PreferencesWithMultipleDefinitionsTest" do
245
242
  before do
243
+ User.preference_definitions.clear
246
244
  User.preference :notifications, :default => true
247
245
  User.preference :color, :string, :default => 'red'
248
- @user = new_user
246
+ @user = build(:user)
249
247
  end
250
248
 
251
249
  it "test_should_only_have_default_preferences" do
252
- assert_equal e = {'notifications' => true, 'color' => 'red'}, @user.preferences
250
+ expect(@user.preferences).to eq ({'notifications' => true, 'color' => 'red'})
253
251
  end
254
252
  end
255
253
 
256
- #------------------------------------------------------------------------------
254
+ #------------------------------------------------------------------------------
257
255
  describe "PreferencesAfterBeingCreatedTest" do
258
256
  before do
259
257
  User.preference :notifications, :default => true
260
- @user = create_user
258
+ @user = create(:user)
261
259
  end
262
260
 
263
261
  it "test_should_not_have_any_stored_preferences" do
264
- assert @user.stored_preferences.empty?
262
+ expect(@user.stored_preferences.empty?).to eq true
265
263
  end
266
264
  end
267
265
 
@@ -270,7 +268,7 @@ describe "ModelPreferenceTest" do
270
268
  before do
271
269
  User.preference :notifications, :default => true
272
270
  User.preference :rate, :float, :default => 1.0
273
- @user = create_user
271
+ @user = create(:user)
274
272
  end
275
273
 
276
274
  it "test_should_raise_exception_if_invalid_preference_read" do
@@ -280,28 +278,28 @@ describe "ModelPreferenceTest" do
280
278
  end
281
279
 
282
280
  it "test_use_default_value_if_not_stored" do
283
- assert_equal true, @user.preferred(:notifications)
281
+ expect(@user.preferred(:notifications)).to eq true
284
282
  end
285
283
 
286
284
  it "test_should_use_group_default_value_if_not_stored" do
287
285
  User.preference :language, :string, :default => 'English', :group_defaults => {:chat => 'Latin'}
288
- assert_equal 'English', @user.preferred(:language)
286
+ expect(@user.preferred(:language)).to eq 'English'
289
287
  end
290
288
 
291
289
  it "test_should_use_stored_value_if_stored" do
292
- create_preference(:owner => @user, :name => 'notifications', :value => false)
293
- assert_equal false, @user.preferred(:notifications)
290
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
291
+ expect(@user.preferred(:notifications)).to eq false
294
292
  end
295
293
 
296
294
  it "test_should_type_cast_based_on_preference_definition" do
297
295
  @user.write_preference(:notifications, 'false')
298
- assert_equal false, @user.preferred(:notifications)
296
+ expect(@user.preferred(:notifications)).to eq false
299
297
  @user.write_preference(:rate, "1.2")
300
- assert_equal 1.2, @user.preferred(:rate)
298
+ expect(@user.preferred(:rate)).to eq 1.2
301
299
  end
302
300
 
303
301
  it "test_should_cache_stored_values" do
304
- create_preference(:owner => @user, :name => 'notifications', :value => false)
302
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
305
303
  assert_queries(1) { @user.preferred(:notifications) }
306
304
  assert_queries(0) { @user.preferred(:notifications) }
307
305
  end
@@ -312,18 +310,18 @@ describe "ModelPreferenceTest" do
312
310
  end
313
311
 
314
312
  it "test_should_use_value_from_preferences_lookup" do
315
- create_preference(:owner => @user, :name => 'notifications', :value => false)
313
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
316
314
  @user.preferences
317
315
 
318
316
  assert_queries(0) { assert_equal false, @user.preferred(:notifications) }
319
317
  end
320
318
 
321
319
  it "test_should_be_able_to_use_prefers_reader" do
322
- assert_equal true, @user.prefers_notifications
320
+ expect(@user.prefers_notifications).to eq true
323
321
  end
324
322
 
325
323
  it "test_should_be_able_to_use_preferred_reader" do
326
- assert_equal true, @user.preferred_notifications
324
+ expect(@user.preferred_notifications).to eq true
327
325
  end
328
326
  end
329
327
 
@@ -331,25 +329,25 @@ describe "ModelPreferenceTest" do
331
329
  describe "PreferencesGroupReaderTest" do
332
330
  before do
333
331
  User.preference :notifications, :default => true
334
- @user = create_user
332
+ @user = create(:user)
335
333
  end
336
334
 
337
335
  it "test_should_use_default_value_if_not_stored" do
338
- assert_equal true, @user.preferred(:notifications, :chat)
336
+ expect(@user.preferred(:notifications, :chat)).to eq true
339
337
  end
340
338
 
341
339
  it "test_should_use_group_default_value_if_not_stored" do
342
340
  User.preference :language, :string, :default => 'English', :group_defaults => {:chat => 'Latin'}
343
- assert_equal 'Latin', @user.preferred(:language, :chat)
341
+ expect(@user.preferred(:language, :chat)).to eq 'Latin'
344
342
  end
345
343
 
346
344
  it "test_should_use_stored_value_if_stored" do
347
- create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
348
- assert_equal false, @user.preferred(:notifications, :chat)
345
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
346
+ expect(@user.preferred(:notifications, :chat)).to eq false
349
347
  end
350
348
 
351
349
  it "test_should_cache_stored_values" do
352
- create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
350
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
353
351
  assert_queries(1) { @user.preferred(:notifications, :chat) }
354
352
  assert_queries(0) { @user.preferred(:notifications, :chat) }
355
353
  end
@@ -360,52 +358,52 @@ describe "ModelPreferenceTest" do
360
358
  end
361
359
 
362
360
  it "test_should_use_value_from_preferences_lookup" do
363
- create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
361
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
364
362
  @user.preferences(:chat)
365
363
 
366
364
  assert_queries(0) { assert_equal false, @user.preferred(:notifications, :chat) }
367
365
  end
368
366
 
369
367
  it "test_should_be_able_to_use_prefers_reader" do
370
- assert_equal true, @user.prefers_notifications(:chat)
368
+ expect(@user.prefers_notifications(:chat)).to eq true
371
369
  end
372
370
 
373
371
  it "test_should_be_able_to_use_preferred_reader" do
374
- assert_equal true, @user.preferred_notifications(:chat)
372
+ expect(@user.preferred_notifications(:chat)).to eq true
375
373
  end
376
374
  end
377
375
 
378
376
  #------------------------------------------------------------------------------
379
377
  describe "PreferencesARGroupReaderTest" do
380
378
  before do
381
- @car = create_car
379
+ @car = create(:car)
382
380
 
383
381
  User.preference :notifications, :default => true
384
- @user = create_user
382
+ @user = create(:user)
385
383
  end
386
384
 
387
385
  it "test_use_default_value_if_not_stored" do
388
- assert_equal true, @user.preferred(:notifications, @car)
386
+ expect(@user.preferred(:notifications, @car)).to eq true
389
387
  end
390
388
 
391
389
  it "test_should_use_stored_value_if_stored" do
392
- create_preference(:owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
393
- assert_equal false, @user.preferred(:notifications, @car)
390
+ create(:preference, :owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
391
+ expect(@user.preferred(:notifications, @car)).to eq false
394
392
  end
395
393
 
396
394
  it "test_should_use_value_from_preferences_lookup" do
397
- create_preference(:owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
395
+ create(:preference, :owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
398
396
  @user.preferences(@car)
399
397
 
400
398
  assert_queries(0) { assert_equal false, @user.preferred(:notifications, @car) }
401
399
  end
402
400
 
403
401
  it "test_should_be_able_to_use_prefers_reader" do
404
- assert_equal true, @user.prefers_notifications(@car)
402
+ expect(@user.prefers_notifications(@car)).to eq true
405
403
  end
406
404
 
407
405
  it "test_should_be_able_to_use_preferred_reader" do
408
- assert_equal true, @user.preferred_notifications(@car)
406
+ expect(@user.preferred_notifications(@car)).to eq true
409
407
  end
410
408
  end
411
409
 
@@ -413,7 +411,7 @@ describe "ModelPreferenceTest" do
413
411
  describe "PreferencesQueryTest" do
414
412
  before do
415
413
  User.preference :language, :string
416
- @user = create_user
414
+ @user = create(:user)
417
415
  end
418
416
 
419
417
  it "test_should_raise_exception_if_invalid_preference_queried" do
@@ -424,30 +422,30 @@ describe "ModelPreferenceTest" do
424
422
 
425
423
  it "test_should_be_true_if_present" do
426
424
  @user.preferred_language = 'English'
427
- assert_equal true, @user.preferred?(:language)
425
+ expect(@user.preferred?(:language)).to eq true
428
426
  end
429
427
 
430
428
  it "test_should_be_false_if_not_present" do
431
- assert_equal false, @user.preferred?(:language)
429
+ expect(@user.preferred?(:language)).to eq false
432
430
  end
433
431
 
434
432
  it "test_should_use_stored_value_if_stored" do
435
- create_preference(:owner => @user, :name => 'language', :value => 'English')
436
- assert_equal true, @user.preferred?(:language)
433
+ create(:preference, :owner => @user, :name => 'language', :value => 'English')
434
+ expect(@user.preferred?(:language)).to eq true
437
435
  end
438
436
 
439
437
  it "test_should_cache_stored_values" do
440
- create_preference(:owner => @user, :name => 'language', :value => 'English')
438
+ create(:preference, :owner => @user, :name => 'language', :value => 'English')
441
439
  assert_queries(1) { @user.preferred?(:language) }
442
440
  assert_queries(0) { @user.preferred?(:language) }
443
441
  end
444
442
 
445
443
  it "test_should_be_able_to_use_prefers_reader" do
446
- assert_equal false, @user.prefers_language?
444
+ expect(@user.prefers_language?).to eq false
447
445
  end
448
446
 
449
447
  it "test_should_be_able_to_use_preferred_reader" do
450
- assert_equal false, @user.preferred_language?
448
+ expect(@user.preferred_language?).to eq false
451
449
  end
452
450
  end
453
451
 
@@ -455,67 +453,67 @@ describe "ModelPreferenceTest" do
455
453
  describe "PreferencesGroupQueryTest" do
456
454
  before do
457
455
  User.preference :language, :string
458
- @user = create_user
456
+ @user = create(:user)
459
457
  end
460
458
 
461
459
  it "test_should_be_true_if_present" do
462
460
  @user.preferred_language = 'English', :chat
463
- assert_equal true, @user.preferred?(:language, :chat)
461
+ expect(@user.preferred?(:language, :chat)).to eq true
464
462
  end
465
463
 
466
464
  it "test_should_be_false_if_not_present" do
467
- assert_equal false, @user.preferred?(:language, :chat)
465
+ expect(@user.preferred?(:language, :chat)).to eq false
468
466
  end
469
467
 
470
468
  it "test_should_use_stored_value_if_stored" do
471
- create_preference(:owner => @user, :group_type => 'chat', :name => 'language', :value => 'English')
472
- assert_equal true, @user.preferred?(:language, :chat)
469
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'language', :value => 'English')
470
+ expect(@user.preferred?(:language, :chat)).to eq true
473
471
  end
474
472
 
475
473
  it "test_should_cache_stored_values" do
476
- create_preference(:owner => @user, :group_type => 'chat', :name => 'language', :value => 'English')
474
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'language', :value => 'English')
477
475
  assert_queries(1) { @user.preferred?(:language, :chat) }
478
476
  assert_queries(0) { @user.preferred?(:language, :chat) }
479
477
  end
480
478
 
481
479
  it "test_should_be_able_to_use_prefers_reader" do
482
- assert_equal false, @user.prefers_language?(:chat)
480
+ expect(@user.prefers_language?(:chat)).to eq false
483
481
  end
484
482
 
485
483
  it "test_should_be_able_to_use_preferred_reader" do
486
- assert_equal false, @user.preferred_language?(:chat)
484
+ expect(@user.preferred_language?(:chat)).to eq false
487
485
  end
488
486
  end
489
487
 
490
488
  #------------------------------------------------------------------------------
491
489
  describe "PreferencesARGroupQueryTest" do
492
490
  before do
493
- @car = create_car
491
+ @car = create(:car)
494
492
 
495
493
  User.preference :language, :string
496
- @user = create_user
494
+ @user = create(:user)
497
495
  end
498
496
 
499
497
  it "test_should_be_true_if_present" do
500
498
  @user.preferred_language = 'English', @car
501
- assert_equal true, @user.preferred?(:language, @car)
499
+ expect(@user.preferred?(:language, @car)).to eq true
502
500
  end
503
501
 
504
502
  it "test_should_be_false_if_not_present" do
505
- assert_equal false, @user.preferred?(:language, @car)
503
+ expect(@user.preferred?(:language, @car)).to eq false
506
504
  end
507
505
 
508
506
  it "test_should_use_stored_value_if_stored" do
509
- create_preference(:owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'language', :value => 'English')
510
- assert_equal true, @user.preferred?(:language, @car)
507
+ create(:preference, :owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'language', :value => 'English')
508
+ expect(@user.preferred?(:language, @car)).to eq true
511
509
  end
512
510
 
513
511
  it "test_should_be_able_to_use_prefers_reader" do
514
- assert_equal false, @user.prefers_language?(@car)
512
+ expect(@user.prefers_language?(@car)).to eq false
515
513
  end
516
514
 
517
515
  it "test_should_be_able_to_use_preferred_reader" do
518
- assert_equal false, @user.preferred_language?(@car)
516
+ expect(@user.preferred_language?(@car)).to eq false
519
517
  end
520
518
  end
521
519
 
@@ -524,7 +522,7 @@ describe "ModelPreferenceTest" do
524
522
  before do
525
523
  User.preference :notifications, :boolean, :default => true
526
524
  User.preference :language, :string, :default => 'English'
527
- @user = create_user(:login => 'admin')
525
+ @user = create(:user, :login => 'admin')
528
526
  end
529
527
 
530
528
  it "test_should_raise_exception_if_invalid_preference_written" do
@@ -535,31 +533,31 @@ describe "ModelPreferenceTest" do
535
533
 
536
534
  it "test_should_have_same_value_if_not_changed" do
537
535
  @user.write_preference(:notifications, true)
538
- assert_equal true, @user.preferred(:notifications)
536
+ expect(@user.preferred(:notifications)).to eq true
539
537
  end
540
538
 
541
539
  it "test_should_use_new_value_if_changed" do
542
540
  @user.write_preference(:notifications, false)
543
- assert_equal false, @user.preferred(:notifications)
541
+ expect(@user.preferred(:notifications)).to eq false
544
542
  end
545
543
 
546
544
  it "test_should_not_save_record_after_changing_preference" do
547
545
  @user.login = 'test'
548
546
  @user.write_preference(:notifications, false)
549
547
 
550
- assert_equal 'admin', User.find(@user.id).login
548
+ expect(User.find(@user.id).login).to eq 'admin'
551
549
  end
552
550
 
553
551
  it "test_should_not_create_stored_preferences_immediately" do
554
552
  @user.write_preference(:notifications, false)
555
- assert @user.stored_preferences.empty?
553
+ expect(@user.stored_preferences.empty?).to eq true
556
554
  end
557
555
 
558
556
  it "test_should_not_create_stored_preference_if_value_not_changed" do
559
557
  @user.write_preference(:notifications, true)
560
558
  @user.save!
561
559
 
562
- assert_equal 0, @user.stored_preferences.count
560
+ expect(@user.stored_preferences.count).to eq 0
563
561
  end
564
562
 
565
563
  it "test_should_not_create_stored_integer_preference_if_typecast_not_changed" do
@@ -568,7 +566,7 @@ describe "ModelPreferenceTest" do
568
566
  @user.write_preference(:age, '')
569
567
  @user.save!
570
568
 
571
- assert_equal 0, @user.stored_preferences.count
569
+ expect(@user.stored_preferences.count).to eq 0
572
570
  end
573
571
 
574
572
  it "test_should_create_stored_integer_preference_if_typecast_changed" do
@@ -577,49 +575,49 @@ describe "ModelPreferenceTest" do
577
575
  @user.write_preference(:age, '')
578
576
  @user.save!
579
577
 
580
- assert_nil @user.preferred(:age)
581
- assert_equal 1, @user.stored_preferences.count
578
+ expect(@user.preferred(:age)).to eq nil
579
+ expect(@user.stored_preferences.count).to eq 1
582
580
  end
583
581
 
584
582
  it "test_should_create_stored_preference_if_value_changed" do
585
583
  @user.write_preference(:notifications, false)
586
584
  @user.save!
587
585
 
588
- assert_equal 1, @user.stored_preferences.count
586
+ expect(@user.stored_preferences.count).to eq 1
589
587
  end
590
588
 
591
589
  it "test_should_overwrite_existing_stored_preference_if_value_changed" do
592
- preference = create_preference(:owner => @user, :name => 'notifications', :value => true)
590
+ preference = create(:preference, :owner => @user, :name => 'notifications', :value => true)
593
591
 
594
592
  @user.write_preference(:notifications, false)
595
593
  @user.save!
596
594
 
597
595
  preference.reload
598
- assert_equal false, preference.value
596
+ expect(preference.value).to eq false
599
597
  end
600
598
 
601
599
  it "test_should_not_remove_preference_if_set_to_default" do
602
- create_preference(:owner => @user, :name => 'notifications', :value => false)
600
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
603
601
 
604
602
  @user.write_preference(:notifications, true)
605
603
  @user.save!
606
604
  @user.reload
607
605
 
608
- assert_equal 1, @user.stored_preferences.size
606
+ expect(@user.stored_preferences.size).to eq 1
609
607
  preference = @user.stored_preferences.first
610
- assert_equal true, preference.value
608
+ expect(preference.value).to eq true
611
609
  end
612
610
 
613
611
  it "test_should_not_remove_preference_if_set_to_nil" do
614
- create_preference(:owner => @user, :name => 'notifications', :value => false)
612
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
615
613
 
616
614
  @user.write_preference(:notifications, nil)
617
615
  @user.save!
618
616
  @user.reload
619
617
 
620
- assert_equal 1, @user.stored_preferences.size
618
+ expect(@user.stored_preferences.size).to eq 1
621
619
  preference = @user.stored_preferences.first
622
- assert_nil preference.value
620
+ expect(preference.value).to eq nil
623
621
  end
624
622
 
625
623
  it "test_should_not_query_for_old_value_if_preferences_loaded" do
@@ -634,31 +632,31 @@ describe "ModelPreferenceTest" do
634
632
  before do
635
633
  User.preference :notifications, :boolean, :default => true
636
634
  User.preference :language, :string, :default => 'English'
637
- @user = create_user(:login => 'admin')
635
+ @user = create(:user, :login => 'admin')
638
636
  end
639
637
 
640
638
  it "test_should_have_same_value_if_not_changed" do
641
639
  @user.write_preference(:notifications, true, :chat)
642
- assert_equal true, @user.preferred(:notifications, :chat)
640
+ expect(@user.preferred(:notifications, :chat)).to eq true
643
641
  end
644
642
 
645
643
  it "test_should_use_new_value_if_changed" do
646
644
  @user.write_preference(:notifications, false, :chat)
647
- assert_equal false, @user.preferred(:notifications, :chat)
645
+ expect(@user.preferred(:notifications, :chat)).to eq false
648
646
  end
649
647
 
650
648
  it "test_should_not_create_stored_preference_if_value_not_changed" do
651
649
  @user.write_preference(:notifications, true, :chat)
652
650
  @user.save!
653
651
 
654
- assert_equal 0, @user.stored_preferences.count
652
+ expect(@user.stored_preferences.count).to eq 0
655
653
  end
656
654
 
657
655
  it "test_should_create_stored_preference_if_value_changed" do
658
656
  @user.write_preference(:notifications, false, :chat)
659
657
  @user.save!
660
658
 
661
- assert_equal 1, @user.stored_preferences.count
659
+ expect(@user.stored_preferences.count).to eq 1
662
660
  end
663
661
 
664
662
  it "test_should_set_group_attributes_on_stored_preferences" do
@@ -666,53 +664,53 @@ describe "ModelPreferenceTest" do
666
664
  @user.save!
667
665
 
668
666
  preference = @user.stored_preferences.first
669
- assert_equal 'chat', preference.group_type
670
- assert_nil preference.group_id
667
+ expect(preference.group_type).to eq 'chat'
668
+ expect(preference.group_id).to eq nil
671
669
  end
672
670
 
673
671
  it "test_should_overwrite_existing_stored_preference_if_value_changed" do
674
- preference = create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => true)
672
+ preference = create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => true)
675
673
 
676
674
  @user.write_preference(:notifications, false, :chat)
677
675
  @user.save!
678
676
 
679
677
  preference.reload
680
- assert_equal false, preference.value
678
+ expect(preference.value).to eq false
681
679
  end
682
680
  end
683
681
 
684
682
  #------------------------------------------------------------------------------
685
683
  describe "PreferencesARGroupWriterTest" do
686
684
  before do
687
- @car = create_car
685
+ @car = create(:car)
688
686
 
689
687
  User.preference :notifications, :boolean, :default => true
690
688
  User.preference :language, :string, :default => 'English'
691
- @user = create_user(:login => 'admin')
689
+ @user = create(:user, :login => 'admin')
692
690
  end
693
691
 
694
692
  it "test_should_have_same_value_if_not_changed" do
695
693
  @user.write_preference(:notifications, true, @car)
696
- assert_equal true, @user.preferred(:notifications, @car)
694
+ expect(@user.preferred(:notifications, @car)).to eq true
697
695
  end
698
696
 
699
697
  it "test_should_use_new_value_if_changed" do
700
698
  @user.write_preference(:notifications, false, @car)
701
- assert_equal false, @user.preferred(:notifications, @car)
699
+ expect(@user.preferred(:notifications, @car)).to eq false
702
700
  end
703
701
 
704
702
  it "test_should_not_create_stored_preference_if_value_not_changed" do
705
703
  @user.write_preference(:notifications, true, @car)
706
704
  @user.save!
707
705
 
708
- assert_equal 0, @user.stored_preferences.count
706
+ expect(@user.stored_preferences.count).to eq 0
709
707
  end
710
708
 
711
709
  it "test_should_create_stored_preference_if_value_changed" do
712
710
  @user.write_preference(:notifications, false, @car)
713
711
  @user.save!
714
712
 
715
- assert_equal 1, @user.stored_preferences.count
713
+ expect(@user.stored_preferences.count).to eq 1
716
714
  end
717
715
 
718
716
  it "test_should_set_group_attributes_on_stored_preferences" do
@@ -720,8 +718,8 @@ describe "ModelPreferenceTest" do
720
718
  @user.save!
721
719
 
722
720
  preference = @user.stored_preferences.first
723
- assert_equal 'Car', preference.group_type
724
- assert_equal @car.id, preference.group_id
721
+ expect(preference.group_type).to eq 'Car'
722
+ expect(preference.group_id).to eq @car.id
725
723
  end
726
724
  end
727
725
 
@@ -730,29 +728,29 @@ describe "ModelPreferenceTest" do
730
728
  before do
731
729
  User.preference :notifications, :boolean, :default => true
732
730
  User.preference :language, :string, :default => 'English'
733
- @user = create_user
731
+ @user = create(:user)
734
732
 
735
733
  @user.write_preference(:notifications, false)
736
734
  end
737
735
 
738
736
  it "test_should_query_preferences_changed" do
739
- assert_equal true, @user.preferences_changed?
737
+ expect(@user.preferences_changed?).to eq true
740
738
  end
741
739
 
742
740
  it "test_should_query_preference_changed" do
743
- assert_equal true, @user.prefers_notifications_changed?
741
+ expect(@user.prefers_notifications_changed?).to eq true
744
742
  end
745
743
 
746
744
  it "test_should_not_query_preferences_changed_for_group" do
747
- assert_equal false, @user.preferences_changed?(:chat)
745
+ expect(@user.preferences_changed?(:chat)).to eq false
748
746
  end
749
747
 
750
748
  it "test_should_not_query_preference_changed_for_group" do
751
- assert_equal false, @user.prefers_notifications_changed?(:chat)
749
+ expect(@user.prefers_notifications_changed?(:chat)).to eq false
752
750
  end
753
751
 
754
752
  it "test_should_have_preferences_changed" do
755
- assert_equal ['notifications'], @user.preferences_changed
753
+ expect(@user.preferences_changed).to eq ['notifications']
756
754
  end
757
755
 
758
756
  it "test_should_not_build_same_preferences_changed_result" do
@@ -760,16 +758,16 @@ describe "ModelPreferenceTest" do
760
758
  end
761
759
 
762
760
  it "test_should_not_have_preferences_changed_for_group" do
763
- assert_equal [], @user.preferences_changed(:chat)
761
+ expect(@user.preferences_changed(:chat)).to eq []
764
762
  end
765
763
 
766
764
  it "test_should_track_multiple_preferences_changed" do
767
765
  @user.write_preference(:language, 'Latin')
768
- assert_equal ['language', 'notifications'], @user.preferences_changed.sort
766
+ expect(@user.preferences_changed.sort).to eq ['language', 'notifications']
769
767
  end
770
768
 
771
769
  it "test_should_have_preference_changes" do
772
- assert_equal e = {'notifications' => [true, false]}, @user.preference_changes
770
+ expect(@user.preference_changes).to eq ({'notifications' => [true, false]})
773
771
  end
774
772
 
775
773
  it "test_should_not_build_same_preference_changes_result" do
@@ -777,28 +775,28 @@ describe "ModelPreferenceTest" do
777
775
  end
778
776
 
779
777
  it "test_should_have_preference_change" do
780
- assert_equal [true, false], @user.prefers_notifications_change
778
+ expect(@user.prefers_notifications_change).to eq [true, false]
781
779
  end
782
780
 
783
781
  it "test_should_have_preference_was" do
784
- assert_equal true, @user.prefers_notifications_was
782
+ expect(@user.prefers_notifications_was).to eq true
785
783
  end
786
784
 
787
785
  it "test_should_not_have_preference_changes_for_group" do
788
- assert_equal e = {}, @user.preference_changes(:chat)
786
+ expect(@user.preference_changes(:chat)).to eq ({})
789
787
  end
790
788
 
791
789
  it "test_should_not_have_preference_change_for_group" do
792
- assert_nil @user.prefers_notifications_change(:chat)
790
+ expect(@user.prefers_notifications_change(:chat)).to eq nil
793
791
  end
794
792
 
795
793
  it "test_should_have_preference_was_for_group" do
796
- assert_equal true, @user.prefers_notifications_was(:chat)
794
+ expect(@user.prefers_notifications_was(:chat)).to eq true
797
795
  end
798
796
 
799
797
  it "test_should_use_latest_value_for_preference_changes" do
800
798
  @user.write_preference(:notifications, nil)
801
- assert_equal e = {'notifications' => [true, nil]}, @user.preference_changes
799
+ expect(@user.preference_changes).to eq ({'notifications' => [true, nil]})
802
800
  end
803
801
 
804
802
  it "test_should_use_cloned_old_value_for_preference_changes" do
@@ -806,13 +804,13 @@ describe "ModelPreferenceTest" do
806
804
  @user.write_preference(:language, 'Latin')
807
805
 
808
806
  tracked_old_value = @user.preference_changes['language'][0]
809
- assert_equal old_value, tracked_old_value
807
+ expect(tracked_old_value).to eq old_value
810
808
  expect(old_value).to_not be tracked_old_value
811
809
  end
812
810
 
813
811
  it "test_should_track_multiple_preference_changes" do
814
812
  @user.write_preference(:language, 'Latin')
815
- assert_equal e = {'notifications' => [true, false], 'language' => ['English', 'Latin']}, @user.preference_changes
813
+ expect(@user.preference_changes).to eq ({'notifications' => [true, false], 'language' => ['English', 'Latin']})
816
814
  end
817
815
  end
818
816
 
@@ -821,57 +819,57 @@ describe "ModelPreferenceTest" do
821
819
  before do
822
820
  User.preference :notifications, :boolean, :default => true
823
821
  User.preference :language, :string, :default => 'English'
824
- @user = create_user
822
+ @user = create(:user)
825
823
 
826
824
  @user.write_preference(:notifications, false, :chat)
827
825
  end
828
826
 
829
827
  it "test_should_not_query_preferences_changed" do
830
- assert_equal false, @user.preferences_changed?
828
+ expect(@user.preferences_changed?).to eq false
831
829
  end
832
830
 
833
831
  it "test_not_should_query_preference_changed" do
834
- assert_equal false, @user.prefers_notifications_changed?
832
+ expect(@user.prefers_notifications_changed?).to eq false
835
833
  end
836
834
 
837
835
  it "test_should_query_preferences_changed_for_group" do
838
- assert_equal true, @user.preferences_changed?(:chat)
836
+ expect(@user.preferences_changed?(:chat)).to eq true
839
837
  end
840
838
 
841
839
  it "test_should_query_preference_changed_for_group" do
842
- assert_equal true, @user.prefers_notifications_changed?(:chat)
840
+ expect(@user.prefers_notifications_changed?(:chat)).to eq true
843
841
  end
844
842
 
845
843
  it "test_should_have_preferences_changed" do
846
- assert_equal [], @user.preferences_changed
844
+ expect(@user.preferences_changed).to eq []
847
845
  end
848
846
 
849
847
  it "test_should_not_have_preferences_changed_for_group" do
850
- assert_equal ['notifications'], @user.preferences_changed(:chat)
848
+ expect(@user.preferences_changed(:chat)).to eq ['notifications']
851
849
  end
852
850
 
853
851
  it "test_should_have_preference_changes" do
854
- assert_equal e = {}, @user.preference_changes
852
+ expect(@user.preference_changes).to eq ({})
855
853
  end
856
854
 
857
855
  it "test_should_not_have_preference_change" do
858
- assert_nil @user.prefers_notifications_change
856
+ expect(@user.prefers_notifications_change).to eq nil
859
857
  end
860
858
 
861
859
  it "test_should_have_preference_was" do
862
- assert_equal true, @user.prefers_notifications_was
860
+ expect(@user.prefers_notifications_was).to eq true
863
861
  end
864
862
 
865
863
  it "test_should_not_have_preference_changes_for_group" do
866
- assert_equal e = {'notifications' => [true, false]}, @user.preference_changes(:chat)
864
+ expect(@user.preference_changes(:chat)).to eq ({'notifications' => [true, false]})
867
865
  end
868
866
 
869
867
  it "test_should_have_preference_change_for_group" do
870
- assert_equal [true, false], @user.prefers_notifications_change(:chat)
868
+ expect(@user.prefers_notifications_change(:chat)).to eq [true, false]
871
869
  end
872
870
 
873
871
  it "test_should_have_preference_was_for_group" do
874
- assert_equal true, @user.prefers_notifications_was(:chat)
872
+ expect(@user.prefers_notifications_was(:chat)).to eq true
875
873
  end
876
874
  end
877
875
 
@@ -880,21 +878,21 @@ describe "ModelPreferenceTest" do
880
878
  before do
881
879
  User.preference :notifications, :boolean, :default => true
882
880
 
883
- @user = create_user
881
+ @user = create(:user)
884
882
  @user.write_preference(:notifications, false)
885
883
  @user.write_preference(:notifications, true)
886
884
  end
887
885
 
888
886
  it "test_should_not_query_preferences_changed" do
889
- assert_equal false, @user.preferences_changed?
887
+ expect(@user.preferences_changed?).to eq false
890
888
  end
891
889
 
892
890
  it "test_should_not_have_preferences_changed" do
893
- assert_equal [], @user.preferences_changed
891
+ expect(@user.preferences_changed).to eq []
894
892
  end
895
893
 
896
894
  it "test_should_not_have_preference_changes" do
897
- assert_equal e = {}, @user.preference_changes
895
+ expect(@user.preference_changes).to eq ({})
898
896
  end
899
897
  end
900
898
 
@@ -903,18 +901,18 @@ describe "ModelPreferenceTest" do
903
901
  before do
904
902
  User.preference :notifications, :boolean, :default => true
905
903
 
906
- @user = create_user
904
+ @user = create(:user)
907
905
  @user.prefers_notifications_will_change!
908
906
  @user.save
909
907
  end
910
908
 
911
909
  it "test_should_store_preference" do
912
- assert_equal 1, @user.stored_preferences.count
910
+ expect(@user.stored_preferences.count).to eq 1
913
911
 
914
912
  preference = @user.stored_preferences.first
915
- assert_equal nil, preference.group_type
916
- assert_equal nil, preference.group_id
917
- assert_equal true, preference.value
913
+ expect(preference.group_type).to eq nil
914
+ expect(preference.group_id).to eq nil
915
+ expect(preference.value).to eq true
918
916
  end
919
917
  end
920
918
 
@@ -924,18 +922,18 @@ describe "ModelPreferenceTest" do
924
922
  User.preference :notifications, :boolean, :default => true
925
923
  User.preference :language, :string, :default => 'English'
926
924
 
927
- @user = create_user
925
+ @user = create(:user)
928
926
  @user.prefers_notifications_will_change!(:chat)
929
927
  @user.save
930
928
  end
931
929
 
932
930
  it "test_should_store_preference" do
933
- assert_equal 1, @user.stored_preferences.count
931
+ expect(@user.stored_preferences.count).to eq 1
934
932
 
935
933
  preference = @user.stored_preferences.first
936
- assert_equal 'chat', preference.group_type
937
- assert_equal nil, preference.group_id
938
- assert_equal true, preference.value
934
+ expect(preference.group_type).to eq 'chat'
935
+ expect(preference.group_id).to eq nil
936
+ expect(preference.value).to eq true
939
937
  end
940
938
 
941
939
  it "test_should_use_cloned_value_for_tracking_old_value" do
@@ -943,7 +941,7 @@ describe "ModelPreferenceTest" do
943
941
  @user.preferred_language_will_change!
944
942
 
945
943
  tracked_old_value = @user.preferred_language_was
946
- assert_equal old_value, tracked_old_value
944
+ expect(tracked_old_value).to eq old_value
947
945
  expect(old_value).to_not be tracked_old_value
948
946
  end
949
947
  end
@@ -953,18 +951,18 @@ describe "ModelPreferenceTest" do
953
951
  before do
954
952
  User.preference :notifications, :boolean, :default => true
955
953
 
956
- @user = create_user
954
+ @user = create(:user)
957
955
  @user.write_preference(:notifications, false)
958
956
  @user.write_preference(:notifications, false, :chat)
959
957
  @user.reset_prefers_notifications!
960
958
  end
961
959
 
962
960
  it "test_should_revert_to_original_value" do
963
- assert_equal true, @user.preferred(:notifications)
961
+ expect(@user.preferred(:notifications)).to eq true
964
962
  end
965
963
 
966
964
  it "test_should_not_reset_groups" do
967
- assert_equal false, @user.preferred(:notifications, :chat)
965
+ expect(@user.preferred(:notifications, :chat)).to eq false
968
966
  end
969
967
  end
970
968
 
@@ -973,59 +971,60 @@ describe "ModelPreferenceTest" do
973
971
  before do
974
972
  User.preference :notifications, :boolean, :default => true
975
973
 
976
- @user = create_user
974
+ @user = create(:user)
977
975
  @user.write_preference(:notifications, false)
978
976
  @user.write_preference(:notifications, false, :chat)
979
977
  @user.reset_prefers_notifications!(:chat)
980
978
  end
981
979
 
982
980
  it "test_should_revert_to_original_value" do
983
- assert_equal true, @user.preferred(:notifications, :chat)
981
+ expect(@user.preferred(:notifications, :chat)).to eq true
984
982
  end
985
983
 
986
984
  it "test_should_not_reset_default_group" do
987
- assert_equal false, @user.preferred(:notifications)
985
+ expect(@user.preferred(:notifications)).to eq false
988
986
  end
989
987
  end
990
988
 
991
989
  #------------------------------------------------------------------------------
992
990
  describe "PreferencesLookupTest" do
993
991
  before do
992
+ User.preference_definitions.clear
994
993
  User.preference :notifications, :boolean, :default => true
995
994
  User.preference :language, :string, :default => 'English', :group_defaults => {:chat => 'Latin'}
996
995
 
997
- @user = create_user
996
+ @user = create(:user)
998
997
  end
999
998
 
1000
999
  it "test_should_only_have_defaults_if_nothing_customized" do
1001
- assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
1000
+ expect(@user.preferences).to eq ({'notifications' => true, 'language' => 'English'})
1002
1001
  end
1003
1002
 
1004
1003
  it "test_should_merge_defaults_with_unsaved_changes" do
1005
1004
  @user.write_preference(:notifications, false)
1006
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences
1005
+ expect(@user.preferences).to eq ({'notifications' => false, 'language' => 'English'})
1007
1006
  end
1008
1007
 
1009
1008
  it "test_should_merge_defaults_with_saved_changes" do
1010
- create_preference(:owner => @user, :name => 'notifications', :value => false)
1011
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences
1009
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
1010
+ expect(@user.preferences).to eq ({'notifications' => false, 'language' => 'English'})
1012
1011
  end
1013
1012
 
1014
1013
  it "test_should_merge_stored_preferences_with_unsaved_changes" do
1015
- create_preference(:owner => @user, :name => 'notifications', :value => false)
1014
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
1016
1015
  @user.write_preference(:language, 'Latin')
1017
- assert_equal e = {'notifications' => false, 'language' => 'Latin'}, @user.preferences
1016
+ expect(@user.preferences).to eq ({'notifications' => false, 'language' => 'Latin'})
1018
1017
  end
1019
1018
 
1020
1019
  it "test_should_use_unsaved_changes_over_stored_preferences" do
1021
- create_preference(:owner => @user, :name => 'notifications', :value => true)
1020
+ create(:preference, :owner => @user, :name => 'notifications', :value => true)
1022
1021
  @user.write_preference(:notifications, false)
1023
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences
1022
+ expect(@user.preferences).to eq ({'notifications' => false, 'language' => 'English'})
1024
1023
  end
1025
1024
 
1026
1025
  it "test_should_typecast_unsaved_changes" do
1027
1026
  @user.write_preference(:notifications, 'true')
1028
- assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
1027
+ expect(@user.preferences).to eq ({'notifications' => true, 'language' => 'English'})
1029
1028
  end
1030
1029
 
1031
1030
  it "test_should_cache_results" do
@@ -1034,10 +1033,10 @@ describe "ModelPreferenceTest" do
1034
1033
  end
1035
1034
 
1036
1035
  it "test_should_not_query_if_stored_preferences_eager_loaded" do
1037
- create_preference(:owner => @user, :name => 'notifications', :value => false)
1036
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
1038
1037
  user = User.includes(:stored_preferences).where(id: @user.id).first
1039
1038
  assert_queries(0) do
1040
- assert_equal e = {'notifications' => false, 'language' => 'English'}, user.preferences
1039
+ expect(user.preferences).to eq ({'notifications' => false, 'language' => 'English'})
1041
1040
  end
1042
1041
  end
1043
1042
 
@@ -1046,42 +1045,43 @@ describe "ModelPreferenceTest" do
1046
1045
  end
1047
1046
 
1048
1047
  it "test_should_use_preferences_for_prefs" do
1049
- assert_equal @user.preferences, @user.prefs
1048
+ expect(@user.prefs).to eq @user.preferences
1050
1049
  end
1051
1050
  end
1052
1051
 
1053
1052
  #------------------------------------------------------------------------------
1054
1053
  describe "PreferencesGroupLookupTest" do
1055
1054
  before do
1055
+ User.preference_definitions.clear
1056
1056
  User.preference :notifications, :boolean, :default => true
1057
1057
  User.preference :language, :string, :default => 'English', :group_defaults => {:chat => 'Latin'}
1058
1058
 
1059
- @user = create_user
1059
+ @user = create(:user)
1060
1060
  end
1061
1061
 
1062
1062
  it "test_should_only_have_defaults_if_nothing_customized" do
1063
- assert_equal e = {'notifications' => true, 'language' => 'Latin'}, @user.preferences(:chat)
1063
+ expect(@user.preferences(:chat)).to eq ({'notifications' => true, 'language' => 'Latin'})
1064
1064
  end
1065
1065
 
1066
1066
  it "test_should_merge_defaults_with_unsaved_changes" do
1067
1067
  @user.write_preference(:notifications, false, :chat)
1068
- assert_equal e = {'notifications' => false, 'language' => 'Latin'}, @user.preferences(:chat)
1068
+ expect(@user.preferences(:chat)).to eq ({'notifications' => false, 'language' => 'Latin'})
1069
1069
  end
1070
1070
 
1071
1071
  it "test_should_merge_defaults_with_saved_changes" do
1072
- create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
1073
- assert_equal e = {'notifications' => false, 'language' => 'Latin'}, @user.preferences(:chat)
1072
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
1073
+ expect(@user.preferences(:chat)).to eq ({'notifications' => false, 'language' => 'Latin'})
1074
1074
  end
1075
1075
 
1076
1076
  it "test_should_merge_stored_preferences_with_unsaved_changes" do
1077
- create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
1077
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
1078
1078
  @user.write_preference(:language, 'Spanish', :chat)
1079
- assert_equal e = {'notifications' => false, 'language' => 'Spanish'}, @user.preferences(:chat)
1079
+ expect(@user.preferences(:chat)).to eq ({'notifications' => false, 'language' => 'Spanish'})
1080
1080
  end
1081
1081
 
1082
1082
  it "test_should_typecast_unsaved_changes" do
1083
1083
  @user.write_preference(:notifications, 'true', :chat)
1084
- assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
1084
+ expect(@user.preferences).to eq ({'notifications' => true, 'language' => 'English'})
1085
1085
  end
1086
1086
 
1087
1087
  it "test_should_cache_results" do
@@ -1104,79 +1104,82 @@ describe "ModelPreferenceTest" do
1104
1104
  #------------------------------------------------------------------------------
1105
1105
  describe "PreferencesARGroupLookupTest" do
1106
1106
  before do
1107
- @car = create_car
1107
+ @car = create(:car)
1108
1108
 
1109
+ User.preference_definitions.clear
1109
1110
  User.preference :notifications, :boolean, :default => true
1110
1111
  User.preference :language, :string, :default => 'English'
1111
1112
 
1112
- @user = create_user
1113
+ @user = create(:user)
1113
1114
  end
1114
1115
 
1115
1116
  it "test_should_only_have_defaults_if_nothing_customized" do
1116
- assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences(@car)
1117
+ expect(@user.preferences(@car)).to eq ({'notifications' => true, 'language' => 'English'})
1117
1118
  end
1118
1119
 
1119
1120
  it "test_should_merge_defaults_with_unsaved_changes" do
1120
1121
  @user.write_preference(:notifications, false, @car)
1121
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences(@car)
1122
+ expect(@user.preferences(@car)).to eq ({'notifications' => false, 'language' => 'English'})
1122
1123
  end
1123
1124
 
1124
1125
  it "test_should_merge_defaults_with_saved_changes" do
1125
- create_preference(:owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
1126
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences(@car)
1126
+ create(:preference, :owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
1127
+ expect(@user.preferences(@car)).to eq ({'notifications' => false, 'language' => 'English'})
1127
1128
  end
1128
1129
 
1129
1130
  it "test_should_merge_stored_preferences_with_unsaved_changes" do
1130
- create_preference(:owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
1131
+ create(:preference, :owner => @user, :group_type => 'Car', :group_id => @car.id, :name => 'notifications', :value => false)
1131
1132
  @user.write_preference(:language, 'Latin', @car)
1132
- assert_equal e = {'notifications' => false, 'language' => 'Latin'}, @user.preferences(@car)
1133
+ expect(@user.preferences(@car)).to eq ({'notifications' => false, 'language' => 'Latin'})
1133
1134
  end
1134
1135
  end
1135
1136
 
1136
1137
  #------------------------------------------------------------------------------
1137
1138
  describe "PreferencesNilGroupLookupTest" do
1138
1139
  before do
1139
- @car = create_car
1140
+ @car = create(:car)
1140
1141
 
1142
+ User.preference_definitions.clear
1141
1143
  User.preference :notifications, :boolean, :default => true
1142
1144
  User.preference :language, :string, :default => 'English'
1143
1145
 
1144
- @user = create_user
1146
+ @user = create(:user)
1145
1147
  end
1146
1148
 
1147
1149
  it "test_should_only_have_defaults_if_nothing_customized" do
1148
- assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences(nil)
1150
+ expect(@user.preferences(nil)).to eq ({'notifications' => true, 'language' => 'English'})
1149
1151
  end
1150
1152
 
1151
1153
  it "test_should_merge_defaults_with_unsaved_changes" do
1152
1154
  @user.write_preference(:notifications, false)
1153
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences(nil)
1155
+ expect(@user.preferences(nil)).to eq ({'notifications' => false, 'language' => 'English'})
1154
1156
  end
1155
1157
 
1156
1158
  it "test_should_merge_defaults_with_saved_changes" do
1157
- create_preference(:owner => @user, :name => 'notifications', :value => false)
1158
- assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences(nil)
1159
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
1160
+ expect(@user.preferences(nil)).to eq ({'notifications' => false, 'language' => 'English'})
1159
1161
  end
1160
1162
 
1161
1163
  it "test_should_merge_stored_preferences_with_unsaved_changes" do
1162
- create_preference(:owner => @user, :name => 'notifications', :value => false)
1164
+ create(:preference, :owner => @user, :name => 'notifications', :value => false)
1163
1165
  @user.write_preference(:language, 'Latin')
1164
- assert_equal e = {'notifications' => false, 'language' => 'Latin'}, @user.preferences(nil)
1166
+ expect(@user.preferences(nil)).to eq ({'notifications' => false, 'language' => 'Latin'})
1165
1167
  end
1166
1168
  end
1167
1169
 
1168
1170
  #------------------------------------------------------------------------------
1169
1171
  describe "PreferencesLookupWithGroupsTest" do
1170
1172
  before do
1173
+ User.preference_definitions.clear
1171
1174
  User.preference :notifications, :boolean, :default => true
1172
1175
  User.preference :language, :string, :default => 'English'
1173
1176
 
1174
- @user = create_user
1175
- create_preference(:owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
1177
+ @user = create(:user)
1178
+ create(:preference, :owner => @user, :group_type => 'chat', :name => 'notifications', :value => false)
1176
1179
  end
1177
1180
 
1178
1181
  it "test_not_include_group_preferences_by_default" do
1179
- assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
1182
+ expect(@user.preferences).to eq ({'notifications' => true, 'language' => 'English'})
1180
1183
  end
1181
1184
  end
1182
1185
 
@@ -1185,22 +1188,22 @@ describe "ModelPreferenceTest" do
1185
1188
  before do
1186
1189
  User.preference :notifications, :boolean, :default => true
1187
1190
 
1188
- @user = create_user
1191
+ @user = create(:user)
1189
1192
  @user.write_preference(:notifications, false)
1190
1193
  @user.reload
1191
1194
  end
1192
1195
 
1193
1196
  it "test_should_reset_unsaved_preferences" do
1194
- assert_equal true, @user.preferred(:notifications)
1197
+ expect(@user.preferred(:notifications)).to eq true
1195
1198
  end
1196
1199
 
1197
1200
  it "test_should_not_save_reset_preferences" do
1198
1201
  @user.save!
1199
- assert @user.stored_preferences.empty?
1202
+ expect(@user.stored_preferences.empty?).to eq true
1200
1203
  end
1201
1204
 
1202
1205
  it "test_should_reset_preferences" do
1203
- assert_equal e = {'notifications' => true}, @user.preferences
1206
+ expect(@user.preferences).to eq ({'notifications' => true})
1204
1207
  end
1205
1208
 
1206
1209
  it "test_should_clear_query_cache_for_preferences" do
@@ -1208,15 +1211,15 @@ describe "ModelPreferenceTest" do
1208
1211
  end
1209
1212
 
1210
1213
  it "test_should_reset_preferences_changed_query" do
1211
- assert_equal false, @user.preferences_changed?
1214
+ expect(@user.preferences_changed?).to eq false
1212
1215
  end
1213
1216
 
1214
1217
  it "test_should_reset_preferences_changed" do
1215
- assert_equal [], @user.preferences_changed
1218
+ expect(@user.preferences_changed).to eq []
1216
1219
  end
1217
1220
 
1218
1221
  it "test_should_reset_preference_changes" do
1219
- assert_equal e = {}, @user.preference_changes
1222
+ expect(@user.preference_changes).to eq ({})
1220
1223
  end
1221
1224
  end
1222
1225
 
@@ -1225,17 +1228,17 @@ describe "ModelPreferenceTest" do
1225
1228
  before do
1226
1229
  User.preference :notifications, :boolean, :default => true
1227
1230
 
1228
- @user = create_user
1231
+ @user = create(:user)
1229
1232
  @user.write_preference(:notifications, false, :chat)
1230
1233
  @user.reload
1231
1234
  end
1232
1235
 
1233
1236
  it "test_should_reset_unsaved_preferences" do
1234
- assert_equal true, @user.preferred(:notifications, :chat)
1237
+ expect(@user.preferred(:notifications, :chat)).to eq true
1235
1238
  end
1236
1239
 
1237
1240
  it "test_should_reset_preferences" do
1238
- assert_equal e = {'notifications' => true}, @user.preferences(:chat)
1241
+ expect(@user.preferences(:chat)).to eq ({'notifications' => true})
1239
1242
  end
1240
1243
 
1241
1244
  it "test_should_clear_query_cache_for_preferences" do
@@ -1243,15 +1246,15 @@ describe "ModelPreferenceTest" do
1243
1246
  end
1244
1247
 
1245
1248
  it "test_should_reset_preferences_changed_query" do
1246
- assert_equal false, @user.preferences_changed?(:chat)
1249
+ expect(@user.preferences_changed?(:chat)).to eq false
1247
1250
  end
1248
1251
 
1249
1252
  it "test_should_reset_preferences_changed" do
1250
- assert_equal [], @user.preferences_changed(:chat)
1253
+ expect(@user.preferences_changed(:chat)).to eq []
1251
1254
  end
1252
1255
 
1253
1256
  it "test_should_reset_preference_changes" do
1254
- assert_equal e = {}, @user.preference_changes(:chat)
1257
+ expect(@user.preference_changes(:chat)).to eq ({})
1255
1258
  end
1256
1259
  end
1257
1260
 
@@ -1262,8 +1265,8 @@ describe "ModelPreferenceTest" do
1262
1265
  User.preference :language, :string, :default => 'English'
1263
1266
  User.preference :color, :string, :default => 'red'
1264
1267
 
1265
- @user = create_user
1266
- @customized_user = create_user(:login => 'customized',
1268
+ @user = create(:user)
1269
+ @customized_user = create(:user,:login => 'customized',
1267
1270
  :prefers_notifications => false,
1268
1271
  :preferred_language => 'Latin'
1269
1272
  )
@@ -1273,35 +1276,35 @@ describe "ModelPreferenceTest" do
1273
1276
  end
1274
1277
 
1275
1278
  it "test_should_not_find_if_no_preference_matched" do
1276
- assert_equal [], User.with_preferences(:language => 'Italian')
1279
+ expect(User.with_preferences(:language => 'Italian')).to eq []
1277
1280
  end
1278
1281
 
1279
1282
  it "test_should_find_with_null_preference" do
1280
- assert_equal [@user], User.with_preferences(:notifications => nil)
1283
+ expect(User.with_preferences(:notifications => nil)).to eq [@user]
1281
1284
  end
1282
1285
 
1283
1286
  it "test_should_find_with_default_preference" do
1284
- assert_equal [@user], User.with_preferences(:language => 'English')
1287
+ expect(User.with_preferences(:language => 'English')).to eq [@user]
1285
1288
  end
1286
1289
 
1287
1290
  it "test_should_find_with_multiple_default_preferences" do
1288
- assert_equal [@user], User.with_preferences(:notifications => nil, :language => 'English')
1291
+ expect(User.with_preferences(:notifications => nil, :language => 'English')).to eq [@user]
1289
1292
  end
1290
1293
 
1291
1294
  it "test_should_find_with_custom_preference" do
1292
- assert_equal [@customized_user], User.with_preferences(:language => 'Latin')
1295
+ expect(User.with_preferences(:language => 'Latin')).to eq [@customized_user]
1293
1296
  end
1294
1297
 
1295
1298
  it "test_should_find_with_multiple_custom_preferences" do
1296
- assert_equal [@customized_user], User.with_preferences(:notifications => false, :language => 'Latin')
1299
+ expect(User.with_preferences(:notifications => false, :language => 'Latin')).to eq [@customized_user]
1297
1300
  end
1298
1301
 
1299
1302
  it "test_should_find_with_mixed_default_and_custom_preferences" do
1300
- assert_equal [@customized_user], User.with_preferences(:color => 'red', :language => 'Latin')
1303
+ expect(User.with_preferences(:color => 'red', :language => 'Latin')).to eq [@customized_user]
1301
1304
  end
1302
1305
 
1303
1306
  it "test_should_find_with_default_group_preference" do
1304
- assert_equal [@user], User.with_preferences(:chat => {:language => 'English'})
1307
+ expect(User.with_preferences(:chat => {:language => 'English'})).to eq [@user]
1305
1308
  end
1306
1309
 
1307
1310
  it "test_should_find_with_customized_default_group_preference" do
@@ -1309,34 +1312,34 @@ describe "ModelPreferenceTest" do
1309
1312
  @customized_user.preferred_country = 'US', :chat
1310
1313
  @customized_user.save!
1311
1314
 
1312
- assert_equal [@user], User.with_preferences(:chat => {:country => 'UK'})
1315
+ expect(User.with_preferences(:chat => {:country => 'UK'})).to eq [@user]
1313
1316
  end
1314
1317
 
1315
1318
  it "test_should_find_with_multiple_default_group_preferences" do
1316
- assert_equal [@user], User.with_preferences(:chat => {:notifications => nil, :language => 'English'})
1319
+ expect(User.with_preferences(:chat => {:notifications => nil, :language => 'English'})).to eq [@user]
1317
1320
  end
1318
1321
 
1319
1322
  it "test_should_find_with_custom_group_preference" do
1320
- assert_equal [@customized_user], User.with_preferences(:chat => {:language => 'Latin'})
1323
+ expect(User.with_preferences(:chat => {:language => 'Latin'})).to eq [@customized_user]
1321
1324
  end
1322
1325
 
1323
1326
  it "test_should_find_with_multiple_custom_group_preferences" do
1324
- assert_equal [@customized_user], User.with_preferences(:chat => {:notifications => false, :language => 'Latin'})
1327
+ expect(User.with_preferences(:chat => {:notifications => false, :language => 'Latin'})).to eq [@customized_user]
1325
1328
  end
1326
1329
 
1327
1330
  it "test_should_find_with_mixed_default_and_custom_group_preferences" do
1328
- assert_equal [@customized_user], User.with_preferences(:chat => {:color => 'red', :language => 'Latin'})
1331
+ expect(User.with_preferences(:chat => {:color => 'red', :language => 'Latin'})).to eq [@customized_user]
1329
1332
  end
1330
1333
 
1331
1334
  it "test_should_find_with_mixed_basic_and_group_preferences" do
1332
1335
  @customized_user.preferred_language = 'English'
1333
1336
  @customized_user.save!
1334
1337
 
1335
- assert_equal [@customized_user], User.with_preferences(:language => 'English', :chat => {:language => 'Latin'})
1338
+ expect(User.with_preferences(:language => 'English', :chat => {:language => 'Latin'})).to eq [@customized_user]
1336
1339
  end
1337
1340
 
1338
1341
  it "test_should_allow_chaining" do
1339
- assert_equal [@user], User.with_preferences(:language => 'English').with_preferences(:color => 'red')
1342
+ expect(User.with_preferences(:language => 'English').with_preferences(:color => 'red')).to eq [@user]
1340
1343
  end
1341
1344
  end
1342
1345
 
@@ -1347,8 +1350,8 @@ describe "ModelPreferenceTest" do
1347
1350
  User.preference :language, :string, :default => 'English'
1348
1351
  User.preference :color, :string, :default => 'red'
1349
1352
 
1350
- @user = create_user
1351
- @customized_user = create_user(:login => 'customized',
1353
+ @user = create(:user)
1354
+ @customized_user = create(:user, :login => 'customized',
1352
1355
  :prefers_notifications => false,
1353
1356
  :preferred_language => 'Latin'
1354
1357
  )
@@ -1358,35 +1361,35 @@ describe "ModelPreferenceTest" do
1358
1361
  end
1359
1362
 
1360
1363
  it "test_should_not_find_if_no_preference_matched" do
1361
- assert_equal [], User.without_preferences(:color => 'red')
1364
+ expect(User.without_preferences(:color => 'red')).to eq []
1362
1365
  end
1363
1366
 
1364
1367
  it "test_should_find_with_null_preference" do
1365
- assert_equal [@user], User.without_preferences(:notifications => false)
1368
+ expect(User.without_preferences(:notifications => false)).to eq [@user]
1366
1369
  end
1367
1370
 
1368
1371
  it "test_should_find_with_default_preference" do
1369
- assert_equal [@user], User.without_preferences(:language => 'Latin')
1372
+ expect(User.without_preferences(:language => 'Latin')).to eq [@user]
1370
1373
  end
1371
1374
 
1372
1375
  it "test_should_find_with_multiple_default_preferences" do
1373
- assert_equal [@user], User.without_preferences(:language => 'Latin', :notifications => false)
1376
+ expect(User.without_preferences(:language => 'Latin', :notifications => false)).to eq [@user]
1374
1377
  end
1375
1378
 
1376
1379
  it "test_should_find_with_custom_preference" do
1377
- assert_equal [@customized_user], User.without_preferences(:language => 'English')
1380
+ expect(User.without_preferences(:language => 'English')).to eq [@customized_user]
1378
1381
  end
1379
1382
 
1380
1383
  it "test_should_find_with_multiple_custom_preferences" do
1381
- assert_equal [@customized_user], User.without_preferences(:language => 'English', :notifications => nil)
1384
+ expect(User.without_preferences(:language => 'English', :notifications => nil)).to eq [@customized_user]
1382
1385
  end
1383
1386
 
1384
1387
  it "test_should_find_with_mixed_default_and_custom_preferences" do
1385
- assert_equal [@customized_user], User.without_preferences(:language => 'English', :color => 'blue')
1388
+ expect(User.without_preferences(:language => 'English', :color => 'blue')).to eq [@customized_user]
1386
1389
  end
1387
1390
 
1388
1391
  it "test_should_find_with_default_group_preference" do
1389
- assert_equal [@user], User.without_preferences(:chat => {:language => 'Latin'})
1392
+ expect(User.without_preferences(:chat => {:language => 'Latin'})).to eq [@user]
1390
1393
  end
1391
1394
 
1392
1395
  it "test_should_find_with_customized_default_group_preference" do
@@ -1394,34 +1397,34 @@ describe "ModelPreferenceTest" do
1394
1397
  @customized_user.preferred_country = 'US', :chat
1395
1398
  @customized_user.save!
1396
1399
 
1397
- assert_equal [@user], User.without_preferences(:chat => {:country => 'US'})
1400
+ expect(User.without_preferences(:chat => {:country => 'US'})).to eq [@user]
1398
1401
  end
1399
1402
 
1400
1403
  it "test_should_find_with_multiple_default_group_preferences" do
1401
- assert_equal [@user], User.without_preferences(:chat => {:language => 'Latin', :notifications => false})
1404
+ expect(User.without_preferences(:chat => {:language => 'Latin', :notifications => false})).to eq [@user]
1402
1405
  end
1403
1406
 
1404
1407
  it "test_should_find_with_custom_group_preference" do
1405
- assert_equal [@customized_user], User.without_preferences(:chat => {:language => 'English'})
1408
+ expect(User.without_preferences(:chat => {:language => 'English'})).to eq [@customized_user]
1406
1409
  end
1407
1410
 
1408
1411
  it "test_should_find_with_multiple_custom_group_preferences" do
1409
- assert_equal [@customized_user], User.without_preferences(:chat => {:language => 'English', :notifications => nil})
1412
+ expect(User.without_preferences(:chat => {:language => 'English', :notifications => nil})).to eq [@customized_user]
1410
1413
  end
1411
1414
 
1412
1415
  it "test_should_find_with_mixed_default_and_custom_group_preferences" do
1413
- assert_equal [@customized_user], User.without_preferences(:chat => {:language => 'English', :color => 'blue'})
1416
+ expect(User.without_preferences(:chat => {:language => 'English', :color => 'blue'})).to eq [@customized_user]
1414
1417
  end
1415
1418
 
1416
1419
  it "test_should_find_with_mixed_basic_and_group_preferences" do
1417
1420
  @customized_user.preferred_language = 'English'
1418
1421
  @customized_user.save!
1419
1422
 
1420
- assert_equal [@customized_user], User.without_preferences(:language => 'Latin', :chat => {:language => 'English'})
1423
+ expect(User.without_preferences(:language => 'Latin', :chat => {:language => 'English'})).to eq [@customized_user]
1421
1424
  end
1422
1425
 
1423
1426
  it "test_should_allow_chaining" do
1424
- assert_equal [@user], User.without_preferences(:language => 'Latin').without_preferences(:color => 'blue')
1427
+ expect(User.without_preferences(:language => 'Latin').without_preferences(:color => 'blue')).to eq [@user]
1425
1428
  end
1426
1429
  end
1427
1430
  end