Skip to content

Commit c5a3cc7

Browse files
committed
Proove that columns with spaces work as expected when you define the ruby-friendly attribute methods.
1 parent ecdcc1c commit c5a3cc7

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
9191
end
9292

9393
end
94+
95+
context 'with column names that have spaces' do
96+
97+
should 'create record using a custom attribute reader and be able to load it back in' do
98+
value = 'Saved value into a column that has a space in the name.'
99+
record = @edge_class.create! :with_spaces => value
100+
assert_equal value, @edge_class.find(record.id).with_spaces
101+
end
102+
103+
end
94104

95105
context 'with description column' do
96106

test/cases/sqlserver_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class StringDefault < ActiveRecord::Base; end
5454
class SqlServerEdgeSchema < ActiveRecord::Base
5555
attr_accessor :new_id_setting
5656
before_create :set_new_id
57+
def with_spaces
58+
read_attribute :'with spaces'
59+
end
60+
def with_spaces=(value)
61+
write_attribute :'with spaces', value
62+
end
5763
protected
5864
def set_new_id
5965
self[:guid_newid] ||= connection.newid_function if new_id_setting

test/schema/sqlserver_specific_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
t.column :tinyint, :tinyint
8484
t.column :guid, :uniqueidentifier
8585
t.column 'crazy]]quote', :string
86+
t.column 'with spaces', :string
8687
end
8788
execute %|ALTER TABLE [sql_server_edge_schemas] ADD [guid_newid] uniqueidentifier DEFAULT NEWID();|
8889
execute %|ALTER TABLE [sql_server_edge_schemas] ADD [guid_newseqid] uniqueidentifier DEFAULT NEWSEQUENTIALID();| unless sqlserver_azure?

0 commit comments

Comments
 (0)