spec/model_spec.rb in game_machine-0.0.10 vs spec/model_spec.rb in game_machine-0.0.11
- old
+ new
@@ -3,25 +3,29 @@
require 'benchmark'
module GameMachine
describe "model" do
- class ScopedModel < GameMachine::Model
+
+ class TestModel < GameMachine::Model
attribute :health, Integer
attribute :name, String
attribute :defense_skill, Integer
attribute :attack_skill, Integer
- set_id_scope :tm
end
- class TestModel < GameMachine::Model
+ class ScopedModel < GameMachine::Model
attribute :health, Integer
attribute :name, String
attribute :defense_skill, Integer
attribute :attack_skill, Integer
+ attribute :test_models, Array
+ attribute :test_model, TestModel
+ set_id_scope :tm
end
+
let(:scoped_model) do
model = ScopedModel.new(:health => 100, :id => 'myid')
end
let(:scoped_storage_entity) do
@@ -31,10 +35,23 @@
let(:test_model) do
model = TestModel.new(:health => 100, :id => 'myid')
end
+
+ # Unfinished but leaving here for now
+ describe "nesting" do
+ it "should parse correctly" do
+ scoped_model.test_models = []
+ scoped_model.test_models << test_model
+ scoped_model.test_models << test_model
+ scoped_model.test_model = test_model
+ hash = JSON.parse(scoped_model.to_json)
+ ScopedModel.from_hash(hash)
+ end
+ end
+
context :scoped_model do
describe "#unscoped_id" do
it "should return unscoped id" do
scoped_model.id = 'tm|myid'
@@ -58,39 +75,34 @@
describe "#save" do
it "should return true on success" do
- expect(test_model.save).to be_true
+ expect(test_model.save).to be_truthy
end
-
- it "should return false if id is nil" do
- test_model.id = nil
- expect(test_model.save).to be_false
- end
end
describe "#save!" do
- it "should raise an exception if id is nil" do
- test_model.id = nil
- expect {test_model.save!}.to raise_error
+ it "should call datastore.put!" do
+ expect_any_instance_of(GameMachine::Commands::DatastoreCommands).to receive(:put!)
+ test_model.save!
end
it "should not raise an exception if id is not nil" do
expect {test_model.save!}.to_not raise_error
end
end
describe "#to_json" do
it "should set klass" do
model_hash = JSON.parse(test_model.to_json)
- expect(model_hash.has_key?('klass')).to be_true
+ expect(model_hash.has_key?('klass')).to be_truthy
end
end
describe "#to_entity" do
it "should return an entity with json entity" do
- expect(test_model.to_entity.has_json_entity).to be_true
+ expect(test_model.to_entity.has_json_entity).to be_truthy
end
end
describe "#from_entity" do
it "should return a test model" do