Решение на Пета задача - DataModel от Ралица Дарджонова
Обратно към всички решения
Към профила на Ралица Дарджонова
Резултати
- 3 точки от тестове
- 0 бонус точки
- 3 точки общо
- 13 успешни тест(а)
- 12 неуспешни тест(а)
Код
Лог от изпълнението
.F.F.F.F.FF.FFF..F....F.F
Failures:
1) DataModel has attributes and data_model getters
Failure/Error: expect(user_model.attributes).to include :first_name
expected [] to include :first_name
Diff:
@@ -1,2 +1,2 @@
-[:first_name]
+[]
# /tmp/d20161202-15620-4on9os/spec.rb:22:in `block (2 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 has #find_by_<attribute> methods
Failure/Error: expect(user_model.find_by_first_name('Ivan').map(&:id)).to eq [record.id]
NameError:
uninitialized constant #<Class:DataModel>::User
# /tmp/d20161202-15620-4on9os/solution.rb:94:in `block in where'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `map'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `where'
# /tmp/d20161202-15620-4on9os/solution.rb:78:in `block in make_setters_and_getters'
# /tmp/d20161202-15620-4on9os/spec.rb:43:in `block (2 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 reuse ids
Failure/Error: expect(georgi.id).to eq 2
expected: 2
got: 1
(compared using ==)
# /tmp/d20161202-15620-4on9os/spec.rb:71: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 compares by id if both records are saved
Failure/Error: modified_ivan = user_model.where(id: ivan.id).first
NameError:
uninitialized constant #<Class:DataModel>::User
# /tmp/d20161202-15620-4on9os/solution.rb:94:in `block in where'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `map'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `where'
# /tmp/d20161202-15620-4on9os/spec.rb:102: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 finds records by attributes
Failure/Error: records = user_model.where(first_name: 'Ivan').map(&:last_name)
NameError:
uninitialized constant #<Class:DataModel>::User
# /tmp/d20161202-15620-4on9os/solution.rb:94:in `block in where'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `map'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `where'
# /tmp/d20161202-15620-4on9os/spec.rb:125: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.where finds records by multiple attributes
Failure/Error: records = user_model.where(
NameError:
uninitialized constant #<Class:DataModel>::User
# /tmp/d20161202-15620-4on9os/solution.rb:94:in `block in where'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `map'
# /tmp/d20161202-15620-4on9os/solution.rb:93:in `where'
# /tmp/d20161202-15620-4on9os/spec.rb:130: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.where raises an error if the query is by an unknown key
Failure/Error: expect { user_model.where(middle_name: 'Ivanov') }.to raise_error(
expected DataModel::UnknownAttributeError with "Unknown attribute middle_name", got #<DataModel::UnknownAttributeError: DataModel::UnknownAttributeError> with backtrace:
# /tmp/d20161202-15620-4on9os/solution.rb:91:in `block in where'
# /tmp/d20161202-15620-4on9os/solution.rb:90:in `each'
# /tmp/d20161202-15620-4on9os/solution.rb:90:in `where'
# /tmp/d20161202-15620-4on9os/spec.rb:143:in `block (4 levels) in <top (required)>'
# /tmp/d20161202-15620-4on9os/spec.rb:143: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)>'
# /tmp/d20161202-15620-4on9os/spec.rb:143: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) DataModel#delete deletes only the record for which it is called
Failure/Error: ivan.delete
ArgumentError:
wrong number of arguments (given 0, expected 1)
# /tmp/d20161202-15620-4on9os/spec.rb:156:in `delete'
# /tmp/d20161202-15620-4on9os/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)>'
9) DataModel#delete raises an error if the record is not saved
Failure/Error: expect { user_model.new(first_name: 'Ivan').delete }.to raise_error(
expected DataModel::DeleteUnsavedRecordError, got #<NameError: uninitialized constant InstanceMethods::DeleteUnsavedRecordError> with backtrace:
# /tmp/d20161202-15620-4on9os/solution.rb:13:in `delete'
# /tmp/d20161202-15620-4on9os/spec.rb:163:in `block (4 levels) in <top (required)>'
# /tmp/d20161202-15620-4on9os/spec.rb:163: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)>'
# /tmp/d20161202-15620-4on9os/spec.rb:163: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 #update updates the attributes of a record with a given ID
Failure/Error: store.update(2, {id: 2, name: 'Georgi'})
NoMethodError:
undefined method `[]=' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-4on9os/spec.rb:235
# /tmp/d20161202-15620-4on9os/solution.rb:118:in `block in update'
# /tmp/d20161202-15620-4on9os/solution.rb:117:in `each'
# /tmp/d20161202-15620-4on9os/solution.rb:117:in `update'
# /tmp/d20161202-15620-4on9os/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)>'
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 `[]=' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-4on9os/spec.rb:239
# /tmp/d20161202-15620-4on9os/solution.rb:118:in `block in update'
# /tmp/d20161202-15620-4on9os/solution.rb:117:in `each'
# /tmp/d20161202-15620-4on9os/solution.rb:117:in `update'
# /tmp/d20161202-15620-4on9os/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 #delete can delete multiple records with a single query
Failure/Error: store.delete(name: 'Pesho')
NoMethodError:
undefined method `[]' for nil:NilClass
Shared Example Group: "a data store" called from /tmp/d20161202-15620-4on9os/spec.rb:239
# /tmp/d20161202-15620-4on9os/solution.rb:172:in `block (2 levels) in delete'
# /tmp/d20161202-15620-4on9os/solution.rb:171:in `each'
# /tmp/d20161202-15620-4on9os/solution.rb:171:in `block in delete'
# /tmp/d20161202-15620-4on9os/solution.rb:169:in `each'
# /tmp/d20161202-15620-4on9os/solution.rb:169:in `delete'
# /tmp/d20161202-15620-4on9os/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.0341 seconds
25 examples, 12 failures
Failed examples:
rspec /tmp/d20161202-15620-4on9os/spec.rb:21 # DataModel has attributes and data_model getters
rspec /tmp/d20161202-15620-4on9os/spec.rb:39 # DataModel has #find_by_<attribute> methods
rspec /tmp/d20161202-15620-4on9os/spec.rb:62 # DataModel id generation does not reuse ids
rspec /tmp/d20161202-15620-4on9os/spec.rb:92 # DataModel equality comparison compares by id if both records are saved
rspec /tmp/d20161202-15620-4on9os/spec.rb:124 # DataModel.where finds records by attributes
rspec /tmp/d20161202-15620-4on9os/spec.rb:129 # DataModel.where finds records by multiple attributes
rspec /tmp/d20161202-15620-4on9os/spec.rb:142 # DataModel.where raises an error if the query is by an unknown key
rspec /tmp/d20161202-15620-4on9os/spec.rb:151 # DataModel#delete deletes only the record for which it is called
rspec /tmp/d20161202-15620-4on9os/spec.rb:162 # DataModel#delete raises an error if the record is not saved
rspec /tmp/d20161202-15620-4on9os/spec.rb:196 # HashStore behaves like a data store #update updates the attributes of a record with a given ID
rspec /tmp/d20161202-15620-4on9os/spec.rb:196 # ArrayStore behaves like a data store #update updates the attributes of a record with a given ID
rspec /tmp/d20161202-15620-4on9os/spec.rb:218 # ArrayStore behaves like a data store #delete can delete multiple records with a single query
История (3 версии и 2 коментара)
Ралица обнови решението на 29.11.2016 23:37 (преди около 8 години)
Ралица обнови решението на 01.12.2016 16:21 (преди около 8 години)
Ралица обнови решението на 01.12.2016 22:38 (преди около 8 години)