spec/merging_blueprints_spec.rb in gooddata-0.6.0.pre9 vs spec/merging_blueprints_spec.rb in gooddata-0.6.0.pre10

- old
+ new

@@ -2,88 +2,63 @@ require 'pry' describe GoodData::Model::ProjectBlueprint do before(:each) do - @base_blueprint = blueprint = GoodData::Model::ProjectBlueprint.new( - { - :title => "x", - :datasets => [ - { - :name=>"payments", - :columns => [ - {:type=>:attribute, :name=>"id"}, - {:type=>:fact, :name=>"amount"}, - {:type=>:reference, :name=>"user_id", :dataset => "users", :reference => "user_id"}, - ] - }, - { - :name=>"users", - :columns => [ - {:type=>:anchor, :name=>"user_id"}, - {:type=>:fact, :name=>"amount"}] - } - ]}) - - @additional_blueprint = GoodData::Model::ProjectBlueprint.new( - { - :title => "x", - :datasets => [ - { - :name=>"users", - :columns => [ - {:type=>:attribute, :name=>"region"} - ] - } - ]}) + @base_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/test_project_model_spec.json") + @additional_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/model_module.json") @blueprint_with_duplicate = GoodData::Model::ProjectBlueprint.new( { :title => "x", :datasets => [ { - :name=>"users", + :name=>"commits", :columns => [ - {:type=>:fact, :name=>"amount"} + {:type=>"fact", :name=>"lines_changed"} ] } ]}) @conflicting_blueprint = GoodData::Model::ProjectBlueprint.new( { :title => "x", :datasets => [ { - :name=>"users", + :name=>"commits", :columns => [ - {:type=>:attribute, :name=>"amount"} + {:type=>"attribute", :name=>"lines_changed"} ] } ]}) end it "should be possible to merge Schema blueprints" do - first_dataset = @base_blueprint.get_dataset("users").to_hash - additional_blueprint = @additional_blueprint.get_dataset("users").to_hash + first_dataset = @base_blueprint.get_dataset("devs").to_hash + additional_blueprint = @additional_blueprint.get_dataset("devs").to_hash stuff = GoodData::Model.merge_dataset_columns(first_dataset, additional_blueprint) - stuff[:columns].include?({:type=>:attribute, :name=>"region"}).should == true - stuff[:columns].include?({:type=>:fact, :name=>"amount"}).should == true + stuff[:columns].include?({:type=>"attribute", :name=>"region"}).should == true + stuff[:columns].include?({:type=>"anchor", :name=>"id"}).should == true end - it "should pass when merging 2 columns with the same name if all attributes are identical" do - first_dataset = @base_blueprint.get_dataset("users").to_hash - additional_blueprint = @blueprint_with_duplicate.get_dataset("users").to_hash + it "should pass when merging 2 columns with the same name if both columns are identical" do + first_dataset = @base_blueprint.get_dataset("commits").to_hash + additional_blueprint = @blueprint_with_duplicate.get_dataset("commits").to_hash stuff = GoodData::Model.merge_dataset_columns(first_dataset, additional_blueprint) - - stuff[:columns].count.should == 2 - stuff[:columns].include?({:type=>:fact, :name=>"amount"}).should == true - stuff[:columns].include?({:type=>:anchor, :name=>"user_id"}).should == true + stuff[:columns].count.should == 4 + stuff[:columns].include?({:type=>"fact", :name=>"lines_changed"}).should == true + stuff[:columns].group_by {|col| col[:name]}["lines_changed"].count.should == 1 end it "should pass when merging 2 columns with the same name if all attributes are identical" do - first_dataset = @base_blueprint.get_dataset("users").to_hash - additional_blueprint = @conflicting_blueprint.get_dataset("users").to_hash + first_dataset = @base_blueprint.get_dataset("commits").to_hash + additional_blueprint = @conflicting_blueprint.get_dataset("commits").to_hash expect{GoodData::Model.merge_dataset_columns(first_dataset, additional_blueprint)}.to raise_error + end + + it "should be possible to merge directly whole bleuprints. Blueprint is changed in place when merge! is used" do + @base_blueprint.merge!(@additional_blueprint) + @base_blueprint.get_dataset("repos").attributes.include?({:type => "attribute", :name => "department"}) end end \ No newline at end of file