spec/unit/models/model_spec.rb in gooddata-0.6.18 vs spec/unit/models/model_spec.rb in gooddata-0.6.19
- old
+ new
@@ -4,65 +4,75 @@
require 'gooddata/models/model'
describe GoodData::Model do
before(:each) do
- @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")
+ @base_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/blueprints/test_project_model_spec.json")
+ @additional_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/blueprints/model_module.json")
@blueprint_with_duplicate = GoodData::Model::ProjectBlueprint.new(
- {
- :title => "x",
- :datasets => [
- {
- :name => "commits",
- :columns => [
- {:type => "fact", :name => "lines_changed", :description=>"Fact description"}
- ]
- }
- ]})
+ {
+ title: "x",
+ datasets: [{
+ id: "dataset.commits",
+ type: :dataset,
+ columns: [
+ {
+ type: "fact",
+ id: "fact.lines_changed",
+ gd_data_type: 'INT',
+ description: "Fact description"
+ }
+ ]
+ }]
+ })
@conflicting_blueprint = GoodData::Model::ProjectBlueprint.new(
- {
- :title => "x",
- :datasets => [
- {
- :name => "commits",
- :columns => [
- {:type => "attribute", :name => "lines_changed"}
- ]
- }
- ]})
+ {
+ title: 'x',
+ datasets: [{
+ type: :dataset,
+ id: 'dataset.commits',
+ columns: [
+ {
+ type: 'fact',
+ id: 'fact.commits.lines_changed'
+ }
+ ]
+ }]
+ })
end
it "should be possible to merge Schema blueprints" do
- first_dataset = @base_blueprint.find_dataset("devs").to_hash
- additional_blueprint = @additional_blueprint.find_dataset("devs").to_hash
+
+ first_dataset = @base_blueprint.find_dataset("dataset.devs").to_hash
+ additional_blueprint = @additional_blueprint.find_dataset("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 => "anchor", :name => "id"}).should == true
+ expect(GoodData::Model::ProjectBlueprint.new(stuff)).to be_valid
+
+ expect(stuff[:columns].include?({:type => :attribute, :id => "attr.region"})).to be_truthy
+ expect(stuff[:columns].include?({:type => :anchor, :id => "attr.devs.dev_id", title: 'Dev', :folder=>"Anchor folder" })).to be_truthy
end
it "should pass when merging 2 columns with the same name if both columns are identical" do
- first_dataset = @base_blueprint.find_dataset("commits").to_hash
- additional_blueprint = @blueprint_with_duplicate.find_dataset("commits").to_hash
-
+ first_dataset = @base_blueprint.find_dataset("dataset.commits").to_hash
+ additional_blueprint = @blueprint_with_duplicate.find_dataset("dataset.commits").to_hash
stuff = GoodData::Model.merge_dataset_columns(first_dataset, additional_blueprint)
+
+ expect(GoodData::Model::ProjectBlueprint.new(stuff)).to be_valid
- stuff[:columns].count.should == 4
- stuff[:columns].include?({:type => "fact", :name => "lines_changed", :description=>"Fact description"}).should == true
- stuff[:columns].group_by { |col| col[:name] }["lines_changed"].count.should == 1
+ expect(stuff[:columns].count).to eq 6
+ expect(stuff[:columns].include?({ type: :fact, id: "fact.lines_changed", gd_data_type: 'INT', description: "Fact description"})).to be_truthy
+ expect(stuff[:columns].group_by { |col| col[:id] }["fact.lines_changed"].count).to eq 1
end
- it "should pass when merging 2 columns with the same name if all attributes are identical" do
- first_dataset = @base_blueprint.find_dataset("commits").to_hash
- additional_blueprint = @conflicting_blueprint.find_dataset("commits").to_hash
-
+ it "should fail when merging" do
+ first_dataset = @base_blueprint.find_dataset("dataset.commits").to_hash
+ additional_blueprint = @conflicting_blueprint.find_dataset("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.find_dataset("repos").attributes.include?({:type => "attribute", :name => "department"})
+ @base_blueprint.find_dataset("dataset.repos").attributes.include?({ type: "attribute", id: "some_attr_id", :title=>"Repository Name" })
end
-
-end
\ No newline at end of file
+end