chair 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chair/chair.rb +7 -3
- data/lib/chair/version.rb +1 -1
- data/spec/table_spec.rb +11 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a6ec94854da3e028f8aea6f564c9cf63c9b9011
|
4
|
+
data.tar.gz: 8d9c2bb02e94815fcaa7ace97ab291bc0c266e90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 805790821f8a261f79c94c494b8431f700f552ad6aa5df2adc9886c9ad9673db3ff322811b638dabd0d397c02dfe5acbc9bbaaba5083923efcb38bab1f506eeb
|
7
|
+
data.tar.gz: 7828bdc15695f86d5448bff224bd1eeeee9cb42e7dea3662da18f1134fd4ac147eec524c5b4b125a1d219ad62dd66c38d2e907fe6c5eb0d3c94c9fd414b1bc42
|
data/lib/chair/chair.rb
CHANGED
@@ -86,11 +86,15 @@ class Chair
|
|
86
86
|
def insert!(args)
|
87
87
|
args = process_incoming_data(args)
|
88
88
|
if has_primary_key?
|
89
|
-
|
90
|
-
|
91
|
-
else # If our table has a primary key, but can't find it in the data
|
89
|
+
unless args.include? @primary_key
|
90
|
+
# If our table has a primary key, but can't find it in the data
|
92
91
|
raise ArgumentError, 'Missing primary key in record to be inserted'
|
93
92
|
end
|
93
|
+
val = args[@primary_key]
|
94
|
+
if @pk_map.has_key?(val)
|
95
|
+
raise RuntimeError, "Primary key #{val.inspect} already exists in table"
|
96
|
+
end
|
97
|
+
@pk_map[val] = @table.size
|
94
98
|
end
|
95
99
|
row = Row.new(self, @table.size, args)
|
96
100
|
@table << row
|
data/lib/chair/version.rb
CHANGED
data/spec/table_spec.rb
CHANGED
@@ -56,7 +56,7 @@ describe Chair do
|
|
56
56
|
}.to change {table.columns.count}.by(2)
|
57
57
|
end
|
58
58
|
|
59
|
-
describe '
|
59
|
+
describe 'inserting a row' do
|
60
60
|
it 'from a hash' do
|
61
61
|
table = Chair.new :title
|
62
62
|
expect {
|
@@ -70,6 +70,15 @@ describe Chair do
|
|
70
70
|
table.insert!(['Gone with the Wind'])
|
71
71
|
}.to change { table.size }.by(1)
|
72
72
|
end
|
73
|
+
|
74
|
+
it 'with the same primary key raises RuntimeError' do
|
75
|
+
table = Chair.new :title
|
76
|
+
table.set_primary_key! :title
|
77
|
+
table.insert! title: 'Gone with the Wind'
|
78
|
+
expect {
|
79
|
+
table.insert!(['Gone with the Wind'])
|
80
|
+
}.to raise_error RuntimeError, 'Primary key "Gone with the Wind" already exists in table'
|
81
|
+
end
|
73
82
|
end
|
74
83
|
|
75
84
|
describe 'setting primary key' do
|
@@ -84,7 +93,7 @@ describe Chair do
|
|
84
93
|
table = Chair.new
|
85
94
|
expect{
|
86
95
|
table.set_primary_key! :title
|
87
|
-
}.to raise_error ArgumentError,
|
96
|
+
}.to raise_error ArgumentError, 'Column :title does not exist in table'
|
88
97
|
end
|
89
98
|
|
90
99
|
it "fails if there's already a primary key" do
|