activerecord 1.12.1 → 1.12.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,3 +1,18 @@
1
+ *1.12.2* (October 26th, 2005)
2
+
3
+ * Allow symbols to rename columns when using SQLite adapter. #2531 [kevin.clark@gmail.com]
4
+
5
+ * Map Active Record time to SQL TIME. #2575, #2576 [Robby Russell <robby@planetargon.com>]
6
+
7
+ * Clarify semantics of ActiveRecord::Base#respond_to? #2560 [skaes@web.de]
8
+
9
+ * Fixed Association#clear for associations which have not yet been accessed. #2524 [Patrick Lenz <patrick@lenz.sh>]
10
+
11
+ * HABTM finders shouldn't return readonly records. #2525 [Patrick Lenz <patrick@lenz.sh>]
12
+
13
+ * Make all tests runnable on their own. #2521. [Blair Zajac <blair@orcaware.com>]
14
+
15
+
1
16
  *1.12.1* (October 19th, 2005)
2
17
 
3
18
  * Always parenthesize :conditions options so they may be safely combined with STI and constraints.
@@ -59,7 +59,7 @@ module ActiveRecord
59
59
 
60
60
  # Removes all records from this association. Returns +self+ so method calls may be chained.
61
61
  def clear
62
- return self if empty? # forces load_target if hasn't happened already
62
+ return self if length.zero? # forces load_target if hasn't happened already
63
63
  if @options[:exclusively_dependent]
64
64
  destroy_all
65
65
  else
@@ -45,6 +45,7 @@ module ActiveRecord
45
45
  end
46
46
  options[:conditions] = conditions
47
47
  options[:joins] = @join_sql
48
+ options[:readonly] ||= false
48
49
 
49
50
  if options[:order] && @options[:order]
50
51
  options[:order] = "#{options[:order]}, #{@options[:order]}"
@@ -357,7 +357,7 @@ module ActiveRecord #:nodoc:
357
357
  # * <tt>:offset</tt>: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
358
358
  # * <tt>:joins</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed).
359
359
  # The records will be returned read-only since they will have attributes that do not correspond to the table's columns.
360
- # Use <tt>find_by_sql</tt> to circumvent this limitation.
360
+ # Pass :readonly => false to override.
361
361
  # * <tt>:include</tt>: Names associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer
362
362
  # to already defined associations. See eager loading under Associations.
363
363
  # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not
@@ -384,8 +384,10 @@ module ActiveRecord #:nodoc:
384
384
  def find(*args)
385
385
  options = extract_options_from_args!(args)
386
386
 
387
- # :joins implies :readonly => true
388
- options[:readonly] = true if options[:joins]
387
+ # :joins implies :readonly => true if unset.
388
+ if options[:joins] and !options.has_key?(:readonly)
389
+ options[:readonly] = true
390
+ end
389
391
 
390
392
  case args.first
391
393
  when :first
@@ -729,10 +731,11 @@ module ActiveRecord #:nodoc:
729
731
  # is available.
730
732
  def column_methods_hash
731
733
  @dynamic_methods_hash ||= column_names.inject(Hash.new(false)) do |methods, attr|
732
- methods[attr.to_sym] = true
733
- methods["#{attr}=".to_sym] = true
734
- methods["#{attr}?".to_sym] = true
735
- methods["#{attr}_before_type_cast".to_sym] = true
734
+ attr_name = attr.to_s
735
+ methods[attr.to_sym] = attr_name
736
+ methods["#{attr}=".to_sym] = attr_name
737
+ methods["#{attr}?".to_sym] = attr_name
738
+ methods["#{attr}_before_type_cast".to_sym] = attr_name
736
739
  methods
737
740
  end
738
741
  end
@@ -1087,8 +1090,8 @@ module ActiveRecord #:nodoc:
1087
1090
 
1088
1091
  def encode_quoted_value(value)
1089
1092
  quoted_value = connection.quote(value)
1090
- quoted_value = "'#{quoted_value[1..-2].gsub(/\'/, "\\\\'")}'" if quoted_value.include?("\\\'")
1091
- quoted_value
1093
+ quoted_value = "'#{quoted_value[1..-2].gsub(/\'/, "\\\\'")}'" if quoted_value.include?("\\\'") # (for ruby mode) "
1094
+ quoted_value
1092
1095
  end
1093
1096
  end
1094
1097
 
@@ -1110,6 +1113,7 @@ module ActiveRecord #:nodoc:
1110
1113
  def id
1111
1114
  attr_name = self.class.primary_key
1112
1115
  column = column_for_attribute(attr_name)
1116
+ raise ActiveRecordError, "No such primary key column #{attr_name} for table #{table_name}" if column.nil?
1113
1117
  define_read_method(:id, attr_name, column) if self.class.generate_read_methods
1114
1118
  (value = @attributes[attr_name]) && column.type_cast(value)
1115
1119
  end
@@ -1267,6 +1271,11 @@ module ActiveRecord #:nodoc:
1267
1271
  !value.blank? or value == 0
1268
1272
  end
1269
1273
 
1274
+ # Returns true if the given attribute is in the attributes hash
1275
+ def has_attribute?(attr_name)
1276
+ @attributes.has_key?(attr_name.to_s)
1277
+ end
1278
+
1270
1279
  # Returns an array of names for the attributes available on this object sorted alphabetically.
1271
1280
  def attribute_names
1272
1281
  @attributes.keys.sort
@@ -1302,7 +1311,17 @@ module ActiveRecord #:nodoc:
1302
1311
  # A Person object with a name attribute can ask person.respond_to?("name"), person.respond_to?("name="), and
1303
1312
  # person.respond_to?("name?") which will all return true.
1304
1313
  def respond_to?(method, include_priv = false)
1305
- self.class.column_methods_hash[method.to_sym] || respond_to_without_attributes?(method, include_priv)
1314
+ if attr_name = self.class.column_methods_hash[method.to_sym]
1315
+ return true if @attributes.include?(attr_name) || attr_name == self.class.primary_key
1316
+ return false if self.class.read_methods.include?(attr_name)
1317
+ elsif @attributes.include?(method_name = method.to_s)
1318
+ return true
1319
+ elsif md = /(=|\?|_before_type_cast)$/.match(method_name)
1320
+ return true if @attributes.include?(md.pre_match)
1321
+ end
1322
+ # super must be called at the end of the method, because the inherited respond_to?
1323
+ # would return true for generated readers, even if the attribute wasn't present
1324
+ super
1306
1325
  end
1307
1326
 
1308
1327
  # Just freeze the attributes hash, such that associations are still accessible even on destroyed records.
@@ -1422,7 +1441,7 @@ module ActiveRecord #:nodoc:
1422
1441
  # ActiveRecord::Base.generate_read_methods is set to true.
1423
1442
  def define_read_methods
1424
1443
  self.class.columns_hash.each do |name, column|
1425
- unless column.primary || self.class.serialized_attributes[name] || respond_to_without_attributes?(name)
1444
+ unless self.class.serialized_attributes[name] || respond_to_without_attributes?(name)
1426
1445
  define_read_method(name.to_sym, name, column)
1427
1446
  end
1428
1447
  end
@@ -1432,15 +1451,12 @@ module ActiveRecord #:nodoc:
1432
1451
  def define_read_method(symbol, attr_name, column)
1433
1452
  cast_code = column.type_cast_code('v')
1434
1453
  access_code = cast_code ? "(v=@attributes['#{attr_name}']) && #{cast_code}" : "@attributes['#{attr_name}']"
1435
- body = access_code
1436
1454
 
1437
- # The following 3 lines behave exactly like method_missing if the
1438
- # attribute isn't present.
1439
- unless symbol == :id
1440
- body = body.insert(0, "raise NoMethodError, 'missing attribute: #{attr_name}', caller unless @attributes.has_key?('#{attr_name}'); ")
1455
+ unless attr_name.to_s == self.class.primary_key.to_s
1456
+ access_code = access_code.insert(0, "raise NoMethodError, 'missing attribute: #{attr_name}', caller unless @attributes.has_key?('#{attr_name}'); ")
1441
1457
  end
1442
- self.class.class_eval("def #{symbol}; #{body} end")
1443
1458
 
1459
+ self.class.class_eval("def #{symbol}; #{access_code}; end")
1444
1460
  self.class.read_methods[attr_name] = true unless symbol == :id
1445
1461
  end
1446
1462
 
@@ -110,7 +110,7 @@ module ActiveRecord
110
110
  :float => { :name => "float" },
111
111
  :datetime => { :name => "datetime" },
112
112
  :timestamp => { :name => "datetime" },
113
- :time => { :name => "datetime" },
113
+ :time => { :name => "time" },
114
114
  :date => { :name => "date" },
115
115
  :binary => { :name => "blob" },
116
116
  :boolean => { :name => "tinyint", :limit => 1 }
@@ -61,7 +61,7 @@ module ActiveRecord
61
61
  :float => { :name => "float" },
62
62
  :datetime => { :name => "timestamp" },
63
63
  :timestamp => { :name => "timestamp" },
64
- :time => { :name => "timestamp" },
64
+ :time => { :name => "time" },
65
65
  :date => { :name => "date" },
66
66
  :binary => { :name => "bytea" },
67
67
  :boolean => { :name => "boolean" }
@@ -280,10 +280,12 @@ module ActiveRecord
280
280
  def copy_table(from, to, options = {}) #:nodoc:
281
281
  create_table(to, options) do |@definition|
282
282
  columns(from).each do |column|
283
- column_name = options[:rename][column.name] if
284
- options[:rename][column.name] if options[:rename]
285
-
286
- @definition.column(column_name || column.name, column.type,
283
+ column_name = options[:rename] ?
284
+ (options[:rename][column.name] ||
285
+ options[:rename][column.name.to_sym] ||
286
+ column.name) : column.name
287
+
288
+ @definition.column(column_name, column.type,
287
289
  :limit => column.limit, :default => column.default,
288
290
  :null => column.null)
289
291
  end
@@ -216,21 +216,18 @@ class Fixtures < YAML::Omap
216
216
  DEFAULT_FILTER_RE = /\.ya?ml$/
217
217
 
218
218
  def self.instantiate_fixtures(object, table_name, fixtures, load_instances=true)
219
- old_logger_level = ActiveRecord::Base.logger.level
220
- ActiveRecord::Base.logger.level = Logger::ERROR
221
-
222
219
  object.instance_variable_set "@#{table_name.to_s.gsub('.','_')}", fixtures
223
220
  if load_instances
224
- fixtures.each do |name, fixture|
225
- if model = fixture.find
226
- object.instance_variable_set "@#{name}", model
221
+ ActiveRecord::Base.logger.silence do
222
+ fixtures.each do |name, fixture|
223
+ if model = fixture.find
224
+ object.instance_variable_set "@#{name}", model
225
+ end
227
226
  end
228
227
  end
229
228
  end
230
-
231
- ActiveRecord::Base.logger.level = old_logger_level
232
229
  end
233
-
230
+
234
231
  def self.instantiate_all_loaded_fixtures(object, load_instances=true)
235
232
  all_loaded_fixtures.each do |table_name, fixtures|
236
233
  Fixtures.instantiate_fixtures(object, table_name, fixtures, load_instances)
@@ -241,34 +238,29 @@ class Fixtures < YAML::Omap
241
238
  self.all_loaded_fixtures = {}
242
239
 
243
240
  def self.create_fixtures(fixtures_directory, *table_names)
241
+ table_names = table_names.flatten.map { |n| n.to_s }
244
242
  connection = block_given? ? yield : ActiveRecord::Base.connection
245
- old_logger_level = ActiveRecord::Base.logger.level
246
-
247
- begin
248
- ActiveRecord::Base.logger.level = Logger::ERROR
249
243
 
244
+ ActiveRecord::Base.logger.silence do
250
245
  fixtures_map = {}
251
- fixtures = table_names.flatten.map do |table_name|
246
+ fixtures = table_names.map do |table_name|
252
247
  fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, File.join(fixtures_directory, table_name.to_s))
253
248
  end
254
249
  all_loaded_fixtures.merge! fixtures_map
255
-
256
-
250
+
257
251
  connection.transaction do
258
252
  fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
259
253
  fixtures.each { |fixture| fixture.insert_fixtures }
260
- end
261
254
 
262
- # Cap primary key sequences to max(pk).
263
- if connection.respond_to?(:reset_pk_sequence!)
264
- table_names.flatten.each do |table_name|
265
- connection.reset_pk_sequence!(table_name)
255
+ # Cap primary key sequences to max(pk).
256
+ if connection.respond_to?(:reset_pk_sequence!)
257
+ table_names.each do |table_name|
258
+ connection.reset_pk_sequence!(table_name)
259
+ end
266
260
  end
267
261
  end
268
262
 
269
263
  return fixtures.size > 1 ? fixtures : fixtures.first
270
- ensure
271
- ActiveRecord::Base.logger.level = old_logger_level
272
264
  end
273
265
  end
274
266
 
@@ -436,7 +428,7 @@ module Test #:nodoc:
436
428
  @@already_loaded_fixtures = {}
437
429
 
438
430
  def self.fixtures(*table_names)
439
- table_names = table_names.flatten
431
+ table_names = table_names.flatten.map { |n| n.to_s }
440
432
  self.fixture_table_names |= table_names
441
433
  require_fixture_classes(table_names)
442
434
  setup_fixture_accessors(table_names)
@@ -176,7 +176,7 @@ module ActiveRecord
176
176
  # person = Person.new("first_name" => "David", "phone_number" => "what?")
177
177
  # person.save # => false (and doesn't do the save)
178
178
  # person.errors.empty? # => false
179
- # person.count # => 2
179
+ # person.errors.count # => 2
180
180
  # person.errors.on "last_name" # => "can't be empty"
181
181
  # person.errors.on "phone_number" # => "has invalid format"
182
182
  # person.errors.each_full { |msg| puts msg }
@@ -2,7 +2,7 @@ module ActiveRecord
2
2
  module Version #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 12
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/rakefile CHANGED
@@ -71,7 +71,7 @@ spec = Gem::Specification.new do |s|
71
71
  s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
72
72
  end
73
73
 
74
- s.add_dependency('activesupport', '= 1.2.1' + PKG_BUILD)
74
+ s.add_dependency('activesupport', '= 1.2.2' + PKG_BUILD)
75
75
 
76
76
  s.files.delete "test/fixtures/fixture_database.sqlite"
77
77
  s.files.delete "test/fixtures/fixture_database_2.sqlite"
@@ -96,7 +96,7 @@ class EagerAssociationTest < Test::Unit::TestCase
96
96
  end
97
97
 
98
98
  def test_eager_with_has_many_and_limit
99
- posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2)
99
+ posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2)
100
100
  assert_equal 2, posts.size
101
101
  assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size }
102
102
  end
@@ -566,6 +566,15 @@ class HasManyAssociationsTest < Test::Unit::TestCase
566
566
  assert Client.find_by_id(client_id).nil?
567
567
  end
568
568
 
569
+ def test_clearing_without_initial_access
570
+ firm = companies(:first_firm)
571
+
572
+ firm.clients_of_firm.clear
573
+
574
+ assert_equal 0, firm.clients_of_firm.size
575
+ assert_equal 0, firm.clients_of_firm(true).size
576
+ end
577
+
569
578
  def test_deleting_a_item_which_is_not_in_the_collection
570
579
  force_signal37_to_load_all_clients_of_firm
571
580
  summit = Client.find_first("name = 'Summit'")
@@ -1090,6 +1099,22 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
1090
1099
  assert_equal 3, project.access_level.to_i
1091
1100
  end
1092
1101
 
1102
+ def test_hatbm_attribute_access_and_respond_to
1103
+ project = developers(:jamis).projects[0]
1104
+ assert project.has_attribute?("name")
1105
+ assert project.has_attribute?("joined_on")
1106
+ assert project.has_attribute?("access_level")
1107
+ assert project.respond_to?("name")
1108
+ assert project.respond_to?("name=")
1109
+ assert project.respond_to?("name?")
1110
+ assert project.respond_to?("joined_on")
1111
+ assert project.respond_to?("joined_on=")
1112
+ assert project.respond_to?("joined_on?")
1113
+ assert project.respond_to?("access_level")
1114
+ assert project.respond_to?("access_level=")
1115
+ assert project.respond_to?("access_level?")
1116
+ end
1117
+
1093
1118
  def test_habtm_adding_before_save
1094
1119
  no_of_devels = Developer.count
1095
1120
  no_of_projects = Project.count
@@ -1,3 +1,5 @@
1
+ require 'abstract_unit'
2
+ require 'fixtures/topic'
1
3
  require 'fixtures/reply'
2
4
  require 'fixtures/company'
3
5
  require 'fixtures/developer'
@@ -209,6 +211,13 @@ class BasicsTest < Test::Unit::TestCase
209
211
  end
210
212
  end
211
213
 
214
+ def test_non_attribute_access_and_assignment
215
+ topic = Topic.new
216
+ assert !topic.respond_to?("mumbo")
217
+ assert_raises(NoMethodError) { topic.mumbo }
218
+ assert_raises(NoMethodError) { topic.mumbo = 5 }
219
+ end
220
+
212
221
  def test_preserving_date_objects
213
222
  # SQL Server doesn't have a separate column type just for dates, so all are returned as time
214
223
  if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
@@ -1,6 +1,5 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
1
  require 'test/unit'
2
+ require 'abstract_unit'
4
3
  require 'active_support/class_inheritable_attributes'
5
4
 
6
5
  class A
@@ -30,4 +29,4 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase
30
29
  assert_equal [ :one, :two, :four ], D.read_inheritable_attribute("first")
31
30
  assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
32
31
  end
33
- end
32
+ end
@@ -2,18 +2,16 @@ require 'abstract_unit'
2
2
  require 'fixtures/topic'
3
3
 
4
4
  class TestColumnAlias < Test::Unit::TestCase
5
+ fixtures :topics
6
+
7
+ QUERY = if 'OCI' == ActiveRecord::Base.connection.adapter_name
8
+ 'SELECT id AS pk FROM topics WHERE ROWNUM < 2'
9
+ else
10
+ 'SELECT id AS pk FROM topics'
11
+ end
5
12
 
6
13
  def test_column_alias
7
- topic = Topic.find(1)
8
- if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
9
- if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
10
- records = topic.connection.select_all("SELECT id AS pk FROM topics WHERE ROWNUM < 2")
11
- assert_equal("pk", records[0].keys[0])
12
- end
13
- else
14
- records = topic.connection.select_all("SELECT id AS pk FROM topics")
15
- assert_equal("pk", records[0].keys[0])
16
- end
14
+ records = Topic.connection.select_all(QUERY)
15
+ assert_equal 'pk', records[0].keys[0]
17
16
  end
18
-
19
17
  end
@@ -69,7 +69,7 @@ end
69
69
 
70
70
 
71
71
  class HasAndBelongsToManyScopingTest< Test::Unit::TestCase
72
- fixtures :posts, :categories
72
+ fixtures :posts, :categories, :categories_posts
73
73
 
74
74
  def setup
75
75
  @welcome = Post.find(1)
@@ -6,7 +6,7 @@ require 'fixtures/developer'
6
6
  require 'fixtures/post'
7
7
 
8
8
  class FinderTest < Test::Unit::TestCase
9
- fixtures :companies, :topics, :entrants, :developers, :posts
9
+ fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts
10
10
 
11
11
  def test_find
12
12
  assert_equal(topics(:first).title, Topic.find(1).title)
@@ -96,7 +96,13 @@ class FinderTest < Test::Unit::TestCase
96
96
  end
97
97
 
98
98
  def test_find_only_some_columns
99
- assert_raises(NoMethodError) { Topic.find(1, :select => "author_name").title }
99
+ topic = Topic.find(1, :select => "author_name")
100
+ assert_raises(NoMethodError) { topic.title }
101
+ assert_equal "David", topic.author_name
102
+ assert !topic.attribute_present?("title")
103
+ assert !topic.respond_to?("title")
104
+ assert topic.attribute_present?("author_name")
105
+ assert topic.respond_to?("author_name")
100
106
  end
101
107
 
102
108
  def test_find_on_conditions
@@ -259,7 +259,7 @@ class MultipleFixturesTest < Test::Unit::TestCase
259
259
  fixtures :developers, :accounts
260
260
 
261
261
  def test_fixture_table_names
262
- assert_equal([:topics, :developers, :accounts], fixture_table_names)
262
+ assert_equal %w(topics developers accounts), fixture_table_names
263
263
  end
264
264
  end
265
265
 
@@ -269,7 +269,7 @@ class OverlappingFixturesTest < Test::Unit::TestCase
269
269
  fixtures :developers, :accounts
270
270
 
271
271
  def test_fixture_table_names
272
- assert_equal([:topics, :developers, :accounts], fixture_table_names)
272
+ assert_equal %w(topics developers accounts), fixture_table_names
273
273
  end
274
274
  end
275
275
 
@@ -180,6 +180,28 @@ if ActiveRecord::Base.connection.supports_migrations?
180
180
 
181
181
  end
182
182
 
183
+ def test_rename_column_using_symbol_arguments
184
+ begin
185
+ Person.connection.rename_column :people, :first_name, :nick_name
186
+ Person.reset_column_information
187
+ assert Person.column_names.include?("nick_name")
188
+ ensure
189
+ Person.connection.remove_column("people","nick_name")
190
+ Person.connection.add_column("people","first_name", :string)
191
+ end
192
+ end
193
+
194
+ def test_rename_column
195
+ begin
196
+ Person.connection.rename_column "people", "first_name", "nick_name"
197
+ Person.reset_column_information
198
+ assert Person.column_names.include?("nick_name")
199
+ ensure
200
+ Person.connection.remove_column("people","nick_name")
201
+ Person.connection.add_column("people","first_name", :string)
202
+ end
203
+ end
204
+
183
205
  def test_rename_table
184
206
  begin
185
207
  ActiveRecord::Base.connection.create_table :octopuses do |t|
@@ -1,4 +1,4 @@
1
- require 'abstract_unit'
1
+ require "#{File.dirname(__FILE__)}/abstract_unit"
2
2
  require 'fixtures/topic'
3
3
  require 'fixtures/subscriber'
4
4
  require 'fixtures/movie'
@@ -16,7 +16,7 @@ class PrimaryKeysTest < Test::Unit::TestCase
16
16
  topic = Topic.new
17
17
  topic.title = "New Topic"
18
18
  assert_equal(nil, topic.id)
19
- assert_nothing_raised{ topic.save }
19
+ assert_nothing_raised { topic.save! }
20
20
  id = topic.id
21
21
 
22
22
  topicReloaded = Topic.find(id)
@@ -24,16 +24,16 @@ class PrimaryKeysTest < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def test_customized_primary_key_auto_assigns_on_save
27
+ Keyboard.delete_all
27
28
  keyboard = Keyboard.new(:name => 'HHKB')
28
- assert_nothing_raised { keyboard.save }
29
- assert keyboard.id
29
+ assert_nothing_raised { keyboard.save! }
30
30
  assert_equal keyboard.id, Keyboard.find_by_name('HHKB').id
31
31
  end
32
32
 
33
33
  def test_customized_primary_key_can_be_get_before_saving
34
34
  keyboard = Keyboard.new
35
- assert_respond_to(keyboard, :key_number)
36
- assert_nothing_raised { keyboard.key_number }
35
+ assert_nil keyboard.id
36
+ assert_nothing_raised { assert_nil keyboard.key_number }
37
37
  end
38
38
 
39
39
  def test_customized_string_primary_key_settable_before_save
@@ -1,31 +1,41 @@
1
1
  require 'abstract_unit'
2
- require 'fixtures/topic'
2
+ require 'fixtures/developer'
3
+ require 'fixtures/project'
3
4
 
4
5
  class ReadOnlyTest < Test::Unit::TestCase
5
- fixtures :topics
6
+ fixtures :developers, :projects, :developers_projects
6
7
 
7
8
  def test_cant_save_readonly_record
8
- topic = Topic.find(:first)
9
- assert !topic.readonly?
9
+ dev = Developer.find(:first)
10
+ assert !dev.readonly?
10
11
 
11
- topic.readonly!
12
- assert topic.readonly?
12
+ dev.readonly!
13
+ assert dev.readonly?
13
14
 
14
15
  assert_nothing_raised do
15
- topic.content = 'Luscious forbidden fruit.'
16
+ dev.name = 'Luscious forbidden fruit.'
17
+ assert !dev.save
18
+ dev.name = 'Forbidden.'
16
19
  end
17
-
18
- assert_raise(ActiveRecord::ReadOnlyRecord) { topic.save }
19
- assert_raise(ActiveRecord::ReadOnlyRecord) { topic.save! }
20
+ assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save }
21
+ assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save! }
20
22
  end
21
23
 
22
24
  def test_find_with_readonly_option
23
- Topic.find(:all).each { |t| assert !t.readonly? }
24
- Topic.find(:all, :readonly => false).each { |t| assert !t.readonly? }
25
- Topic.find(:all, :readonly => true).each { |t| assert t.readonly? }
25
+ Developer.find(:all).each { |d| assert !d.readonly? }
26
+ Developer.find(:all, :readonly => false).each { |d| assert !d.readonly? }
27
+ Developer.find(:all, :readonly => true).each { |d| assert d.readonly? }
26
28
  end
27
29
 
28
30
  def test_find_with_joins_option_implies_readonly
29
- Topic.find(:all, :joins => '').each { |t| assert t.readonly? }
31
+ Developer.find(:all, :joins => '').each { |d| assert d.readonly? }
32
+ Developer.find(:all, :joins => '', :readonly => false).each { |d| assert !d.readonly? }
33
+ end
34
+
35
+ def test_habtm_find_readonly
36
+ dev = Developer.find(:first)
37
+ dev.projects.each { |p| assert !p.readonly? }
38
+ dev.projects.find(:all) { |p| assert !p.readonly? }
39
+ dev.projects.find(:all, :readonly => true) { |p| assert p.readonly? }
30
40
  end
31
41
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.12.1
7
- date: 2005-10-19
6
+ version: 1.12.2
7
+ date: 2005-10-26 00:00:00 +02:00
8
8
  summary: Implements the ActiveRecord pattern for ORM.
9
9
  require_paths:
10
10
  - lib
@@ -26,6 +26,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
26
26
  version: 0.0.0
27
27
  version:
28
28
  platform: ruby
29
+ signing_key:
30
+ cert_chain:
29
31
  authors:
30
32
  - David Heinemeier Hansson
31
33
  files:
@@ -268,5 +270,5 @@ dependencies:
268
270
  -
269
271
  - "="
270
272
  - !ruby/object:Gem::Version
271
- version: 1.2.1
273
+ version: 1.2.2
272
274
  version: