diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 822e6b3..2e4d4b3 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -57,5 +57,12 @@ describe Domain do Domain.stub_chain('find_by_name.user_id').and_return(domain.user_id + 1) domain.should have(1).errors_on(:name) end + + it "queries domains corectly in index" do + wheres = Domain.accessible_by(ability).where_values + joins = Domain.accessible_by(ability).joins_values.map{|j| [j._name, j._type]} + wheres.should == ["(`permissions`.`user_id` = #{user.id}) OR (`domains`.`user_id` = #{user.id})"] + joins.should == [[:permissions, Arel::Nodes::OuterJoin]] + end end diff --git a/spec/models/record_spec.rb b/spec/models/record_spec.rb index bf3fb09..ce8854f 100644 --- a/spec/models/record_spec.rb +++ b/spec/models/record_spec.rb @@ -16,4 +16,30 @@ describe Record do a_record.max_records_per_domain a_record.should be_valid end + + def record_joins_expectations(joins) + # joins == [{:domain => Squeel(:permissions, outer)}] + joins.size.should == 1 + joins.first.should be_an_instance_of(Hash) + domain_joins = joins.first[:domain] + domain_joins.size.should == 1 + domain_joins.first[:domain]._name.should == :permissions + domain_joins.first[:domain]._type.should == Arel::Nodes::OuterJoin + end + + it "queries records corectly in index" do + wheres = Record.accessible_by(ability).where_values + joins = Record.accessible_by(ability).joins_values + wheres.should == ["(`permissions`.`user_id` = #{user.id}) OR (`domains`.`user_id` = #{user.id})"] + record_joins_expectations(joins) + end + + it "queries A records corectly in index" do + wheres = A.accessible_by(ability).where_values + joins = A.accessible_by(ability).joins_values + wheres.size.should == 2 + wheres.second.should == "(`permissions`.`user_id` = #{user.id}) OR ((`records`.`user_id` = #{user.id}) OR (`domains`.`user_id` = #{user.id}))" + record_joins_expectations(joins) + end + end diff --git a/spec/support/rspec.rb b/spec/support/rspec.rb index 15dce4c..fff7a44 100644 --- a/spec/support/rspec.rb +++ b/spec/support/rspec.rb @@ -1,6 +1,6 @@ RSpec.configure do |config| config.mock_with :rspec - config.use_transactional_fixtures = true + config.use_transactional_fixtures = false config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus => true diff --git a/spec/support/shared_context/data.rb b/spec/support/shared_context/data.rb index 7eac278..829b5a9 100644 --- a/spec/support/shared_context/data.rb +++ b/spec/support/shared_context/data.rb @@ -38,6 +38,6 @@ shared_context "data" do } let(:host_a_record){create(:a, :content => '127.0.0.1', :domain => host_domain, :user => user)} - let(:permission) {create(:permission, :domain => domain, :user => other_user)} - + let(:permission){create(:permission, :domain => domain, :user => other_user)} + end