spec/query_spec.rb in rasti-db-4.1.0 vs spec/query_spec.rb in rasti-db-4.1.1
- old
+ new
@@ -30,10 +30,12 @@
db[:categories_posts].insert post_id: 1, category_id: 1
db[:categories_posts].insert post_id: 1, category_id: 2
db[:categories_posts].insert post_id: 2, category_id: 2
db[:categories_posts].insert post_id: 2, category_id: 3
db[:categories_posts].insert post_id: 3, category_id: 3
+
+ db[:countries].insert name: 'Argentina', population: 40000000, language_id: 1
end
let(:users_query) { Rasti::DB::Query.new collection_class: Users, dataset: db[:users], environment: environment }
let(:posts_query) { Rasti::DB::Query.new collection_class: Posts, dataset: db[:posts], environment: environment }
@@ -42,10 +44,12 @@
let(:people_query) { Rasti::DB::Query.new collection_class: People, dataset: db[:people], environment: environment }
let(:languages_query) { Rasti::DB::Query.new collection_class: Languages, dataset: custom_db[:languages], environment: environment }
+ let(:countries_query) { Rasti::DB::Query.new collection_class: Countries, dataset: db[:countries], environment: environment }
+
it 'Count' do
users_query.count.must_equal 10
end
it 'All' do
@@ -162,9 +166,28 @@
people_query.select_computed_attributes(:full_name)
.where(document_number: 'document_1')
.all
.must_equal [person_expected]
end
+ end
+
+ describe 'Ignore undefined attributes' do
+
+ it 'First level' do
+ countries_query.raw.first.must_equal id: 1,
+ name: 'Argentina',
+ population: 40000000,
+ language_id: 1
+
+ [countries_query.detect(id: 1), countries_query.where(id: 1).order(:name).last, countries_query.all.first].each do |country|
+ country.must_equal Country.new(language_id: 1, id: 1, name: 'Argentina')
+ end
+ end
+
+ it 'Graph nested' do
+ languages_query.graph(:countries).first.countries.must_equal [Country.new(language_id: 1, id: 1, name: 'Argentina')]
+ end
+
end
it 'Map' do
users_query.map(&:name).must_equal db[:users].map(:name)
end
\ No newline at end of file