Browse Source

lists queries tests considering permissions, tweaks

(for the recent Squeel integration used for outer joins)
pull/1/head
Nicolae Claudius 13 years ago
parent
commit
bc1b8a9140
  1. 7
      spec/models/domain_spec.rb
  2. 26
      spec/models/record_spec.rb
  3. 2
      spec/support/rspec.rb
  4. 2
      spec/support/shared_context/data.rb

7
spec/models/domain_spec.rb

@ -58,4 +58,11 @@ describe Domain do
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

26
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

2
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

2
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

Loading…
Cancel
Save