Решение на Пета задача - DataModel от Лазар Дилов
Обратно към всички решения
Към профила на Лазар Дилов
Резултати
- 3 точки от тестове
- 0 бонус точки
- 3 точки общо
- 12 успешни тест(а)
- 13 неуспешни тест(а)
Код
Лог от изпълнението
....FFF.F...FFF..FFF..FFF
Failures:
1) DataModel id generation creates id on first save and does not change it
Failure/Error: expect(record.id).to eq id
expected: 2
got: 3
(compared using ==)
# /tmp/d20161202-15620-1og6i95/spec.rb:59:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DataModel id generation does not reuse ids
Failure/Error: expect(ivan.id).to eq 1
expected: 1
got: 4
(compared using ==)
# /tmp/d20161202-15620-1og6i95/spec.rb:65:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
3) DataModel id generation does not break when there are two models with the same store
Failure/Error: expect(ivan.id).to eq 1
expected: 1
got: 5
(compared using ==)
# /tmp/d20161202-15620-1og6i95/spec.rb:83:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
4) DataModel equality comparison uses #equal? if there are no ids
Failure/Error: expect(first_user).to eq first_user
expected: #<#<Class:0x007f1fad25c2a8>:0x007f1fad2630a8 @saved=false, @first_name="Ivan">
got: #<#<Class:0x007f1fad25c2a8>:0x007f1fad2630a8 @saved=false, @first_name="Ivan">
(compared using ==)
Diff:
# /tmp/d20161202-15620-1og6i95/spec.rb:113:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
5) DataModel.where raises an error if the query is by an unknown key
Failure/Error: DataModel::UnknownAttributeError,
NameError:
uninitialized constant DataModel::UnknownAttributeError
# /tmp/d20161202-15620-1og6i95/spec.rb:144:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
6) DataModel#delete deletes only the record for which it is called
Failure/Error: ivan.delete
NoMethodError:
undefined method `delete' for #<#<Class:0x007f1fad2a4260>:0x007f1fad2ab3f8>
# /tmp/d20161202-15620-1og6i95/spec.rb:156:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
7) DataModel#delete raises an error if the record is not saved
Failure/Error: DataModel::DeleteUnsavedRecordError
NameError:
uninitialized constant DataModel::DeleteUnsavedRecordError
# /tmp/d20161202-15620-1og6i95/spec.rb:164:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
8) HashStore behaves like a data store #update updates the attributes of a record with a given ID
Failure/Error: store.update(2, {id: 2, name: 'Georgi'})
NoMethodError:
undefined method `key?' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-1og6i95/spec.rb:235
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `block in update'
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `each'
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `map'
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `update'
# /tmp/d20161202-15620-1og6i95/spec.rb:199:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
9) HashStore behaves like a data store #update only updates records with the correct IDs
Failure/Error: store.update(2, {id: 2, name: 'Sasho'})
NoMethodError:
undefined method `key?' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-1og6i95/spec.rb:235
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `block in update'
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `each'
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `map'
# /tmp/d20161202-15620-1og6i95/solution.rb:55:in `update'
# /tmp/d20161202-15620-1og6i95/spec.rb:210:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
10) HashStore behaves like a data store #delete can delete multiple records with a single query
Failure/Error: expect(store.find({})).to eq [gosho]
expected: [{:id=>3, :name=>"Gosho"}]
got: [{:id=>1, :name=>"Pesho"}, {:id=>2, :name=>"Pesho"}, {:id=>3, :name=>"Gosho"}]
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-[{:id=>3, :name=>"Gosho"}]
+[{:id=>1, :name=>"Pesho"}, {:id=>2, :name=>"Pesho"}, {:id=>3, :name=>"Gosho"}]
Shared Example Group: "a data store" called from /tmp/d20161202-15620-1og6i95/spec.rb:235
# /tmp/d20161202-15620-1og6i95/spec.rb:229:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
11) ArrayStore behaves like a data store #update updates the attributes of a record with a given ID
Failure/Error: store.update(2, {id: 2, name: 'Georgi'})
NoMethodError:
undefined method `key?' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-1og6i95/spec.rb:239
# /tmp/d20161202-15620-1og6i95/solution.rb:29:in `block in update'
# /tmp/d20161202-15620-1og6i95/solution.rb:29:in `select'
# /tmp/d20161202-15620-1og6i95/solution.rb:29:in `update'
# /tmp/d20161202-15620-1og6i95/spec.rb:199:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
12) ArrayStore behaves like a data store #update only updates records with the correct IDs
Failure/Error: store.update(2, {id: 2, name: 'Sasho'})
NoMethodError:
undefined method `key?' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-1og6i95/spec.rb:239
# /tmp/d20161202-15620-1og6i95/solution.rb:29:in `block in update'
# /tmp/d20161202-15620-1og6i95/solution.rb:29:in `select'
# /tmp/d20161202-15620-1og6i95/solution.rb:29:in `update'
# /tmp/d20161202-15620-1og6i95/spec.rb:210:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
13) ArrayStore behaves like a data store #delete can delete multiple records with a single query
Failure/Error: store.delete(name: 'Pesho')
NameError:
undefined local variable or method `obj' for #<ArrayStore:0x007f1fad66dba8>
Shared Example Group: "a data store" called from /tmp/d20161202-15620-1og6i95/spec.rb:239
# /tmp/d20161202-15620-1og6i95/solution.rb:33:in `block in delete'
# /tmp/d20161202-15620-1og6i95/solution.rb:33:in `map'
# /tmp/d20161202-15620-1og6i95/solution.rb:33:in `delete'
# /tmp/d20161202-15620-1og6i95/spec.rb:227:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.05313 seconds
25 examples, 13 failures
Failed examples:
rspec /tmp/d20161202-15620-1og6i95/spec.rb:48 # DataModel id generation creates id on first save and does not change it
rspec /tmp/d20161202-15620-1og6i95/spec.rb:62 # DataModel id generation does not reuse ids
rspec /tmp/d20161202-15620-1og6i95/spec.rb:74 # DataModel id generation does not break when there are two models with the same store
rspec /tmp/d20161202-15620-1og6i95/spec.rb:108 # DataModel equality comparison uses #equal? if there are no ids
rspec /tmp/d20161202-15620-1og6i95/spec.rb:142 # DataModel.where raises an error if the query is by an unknown key
rspec /tmp/d20161202-15620-1og6i95/spec.rb:151 # DataModel#delete deletes only the record for which it is called
rspec /tmp/d20161202-15620-1og6i95/spec.rb:162 # DataModel#delete raises an error if the record is not saved
rspec /tmp/d20161202-15620-1og6i95/spec.rb:196 # HashStore behaves like a data store #update updates the attributes of a record with a given ID
rspec /tmp/d20161202-15620-1og6i95/spec.rb:204 # HashStore behaves like a data store #update only updates records with the correct IDs
rspec /tmp/d20161202-15620-1og6i95/spec.rb:218 # HashStore behaves like a data store #delete can delete multiple records with a single query
rspec /tmp/d20161202-15620-1og6i95/spec.rb:196 # ArrayStore behaves like a data store #update updates the attributes of a record with a given ID
rspec /tmp/d20161202-15620-1og6i95/spec.rb:204 # ArrayStore behaves like a data store #update only updates records with the correct IDs
rspec /tmp/d20161202-15620-1og6i95/spec.rb:218 # ArrayStore behaves like a data store #delete can delete multiple records with a single query
История (5 версии и 9 коментара)
Лазар обнови решението на 28.11.2016 09:00 (преди около 8 години)
Лазар обнови решението на 28.11.2016 21:05 (преди около 8 години)
Лазар обнови решението на 30.11.2016 15:51 (преди около 8 години)
Лазар обнови решението на 30.11.2016 16:32 (преди около 8 години)
Лазар обнови решението на 30.11.2016 18:47 (преди около 8 години)