Browse Source

ability tests, formatting typo, capybara, matchers

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
2f381e5e1a
  1. 27
      spec/models/ability_spec.rb
  2. 2
      spec/models/tld_spec.rb
  3. 2
      spec/spec_helper.rb
  4. 27
      spec/support/shared_context/data.rb

27
spec/models/ability_spec.rb

@ -0,0 +1,27 @@
require 'spec_helper'
# needs "rake db:test:clone" for the "hosts" part
describe Ability do
include_context "data"
it "allows me to manage my domains and their records, and my hosts" do
ability.should be_able_to(:manage, domain)
ability.should be_able_to(:manage, a_record)
ability.should be_able_to(:manage, soa_record)
ability.should_not be_able_to(:delete, soa_record) # SOA deleted only via parent
ability.should be_able_to(:manage, host_a_record)
end
it "denies other user to manage my domains and their records" do
other_user_ability.should_not be_able_to(:manage, domain)
other_user_ability.should_not be_able_to(:manage, a_record)
other_user_ability.should_not be_able_to(:manage, soa_record)
other_user_ability.should_not be_able_to(:manage, host_a_record)
end
it "allows admin to manage other user's hosts" do
admin_ability.should be_able_to(:manage, host_a_record)
end
end

2
spec/models/tld_spec.rb

@ -3,7 +3,7 @@ require 'spec_helper'
describe Tld do
its ".lines" do
Tld.lines.should be_present
Tld.lines.should be_present
end
its ".include" do

2
spec/spec_helper.rb

@ -6,6 +6,8 @@ Spork.prefork do
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require 'cancan/matchers'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)

27
spec/support/shared_context/data.rb

@ -1,6 +1,9 @@
shared_context "data" do
let(:user){create(:user)}
let(:ability){Ability.new(:user => user)}
let(:other_user){create(:user)}
let(:other_user_ability){Ability.new(:user => other_user)}
let(:domain){
domain = build(:domain, :user => user)
@ -9,9 +12,29 @@ shared_context "data" do
domain.soa_record.update_serial!
domain
}
let(:a_record){create(:a, :content => '127.0.0.1', :domain => domain)}
let(:soa_record){domain.soa_record}
# admin is a user that owns host domains
let(:admin){
admin_user = create(:user,
:first_name => 'admin',
:last_name => 'admin',
:email => 'admin@entrydns.net',
:confirmed_at => Time.now
)
admin_user.confirm!
admin_user
}
let(:admin_ability){Ability.new(:user => admin)}
let(:host_domain){
domain = build(:domain, :user => admin, :name => Settings.host_domains.first)
domain.setup(FactoryGirl.generate(:email))
domain.save!
domain.soa_record.update_serial!
domain
}
let(:host_a_record){create(:a, :content => '127.0.0.1', :domain => host_domain, :user => user)}
end

Loading…
Cancel
Save