chair 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 708b6c777ef65da883a84fea3b82efc0fab65d04
4
- data.tar.gz: 6487ea6b33e0a3580ed3dee015e3dee76ef84bf0
3
+ metadata.gz: 5a6ec94854da3e028f8aea6f564c9cf63c9b9011
4
+ data.tar.gz: 8d9c2bb02e94815fcaa7ace97ab291bc0c266e90
5
5
  SHA512:
6
- metadata.gz: ad6141ebfb731b5c310b0f6f3180ad84881418de08e5d5b78d928aa3702c9cdbeacdc39142443cfc7696c74d61bf587be10a37d74e9ee0f24f5e0b9db84b10a0
7
- data.tar.gz: f53d8948344d3dff2afa298c0501b74084590d03301720c94d87ef49e66d0e933380b3c37858bcaf7a73a6c7b494fe508e467c0e9c3b39d2ebef45f6682db355
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
- if args.include? @primary_key
90
- @pk_map[args[@primary_key]] = @table.size
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
@@ -1,3 +1,3 @@
1
1
  class Chair
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
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 'inserts a row' do
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, "Column :title does not exist in table"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chair
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katherine Whitlock