Nicolae Claudius
13 years ago
124 changed files with 1032 additions and 1563 deletions
@ -0,0 +1,21 @@ |
|||||||
|
class PermissionsController < ApplicationController |
||||||
|
active_scaffold :permission do |conf| |
||||||
|
conf.actions.exclude :show, :search |
||||||
|
conf.columns = [:domain, :user, :user_email] |
||||||
|
conf.list.columns = [:domain, :user, :user_email] |
||||||
|
conf.create.columns = [:domain, :user_email] |
||||||
|
conf.update.columns = [:domain, :user_email] |
||||||
|
conf.columns[:user_email].form_ui = :virtual |
||||||
|
conf.columns[:user_email].description = 'user\'s email address, to share with. Ex. jhon.doe@domain.com' |
||||||
|
conf.create.link.label = 'Share Domain' |
||||||
|
# conf.columns[:user_email].search_sql = 'user.email' |
||||||
|
# conf.columns[:user].search_sql = 'CONCAT(first_name, ' ', last_name)' |
||||||
|
end |
||||||
|
before_filter :ensure_nested_under_domain |
||||||
|
|
||||||
|
protected |
||||||
|
|
||||||
|
def beginning_of_chain |
||||||
|
super.readonly(false) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,25 @@ |
|||||||
|
# some common bits of code for records related controllers |
||||||
|
module RecordsControllerCommon |
||||||
|
extend ActiveSupport::Concern |
||||||
|
|
||||||
|
included do |
||||||
|
before_filter :ensure_nested_under_domain |
||||||
|
end |
||||||
|
|
||||||
|
protected |
||||||
|
|
||||||
|
def before_create_save(record) |
||||||
|
record.domain = nested_parent_record |
||||||
|
record.user = record.domain_user |
||||||
|
end |
||||||
|
|
||||||
|
def nested_via_records? |
||||||
|
nested? && nested.association && nested.association.collection? && nested.association.name == :records |
||||||
|
end |
||||||
|
|
||||||
|
# override to close create form after success |
||||||
|
# RecordsController is the only one that does not really need this |
||||||
|
def render_parent? |
||||||
|
nested_singular_association? # || params[:parent_sti] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,32 @@ |
|||||||
|
class Permission < ActiveRecord::Base |
||||||
|
stampable |
||||||
|
|
||||||
|
belongs_to :domain, :inverse_of => :permissions |
||||||
|
belongs_to :user, :inverse_of => :permissions |
||||||
|
|
||||||
|
validates :domain_id, :presence => true |
||||||
|
validates :user_id, :presence => true, :uniqueness => { |
||||||
|
:scope => :domain_id, |
||||||
|
:message => "already is permitted" |
||||||
|
} |
||||||
|
validates :user, :presence => { |
||||||
|
:if => lambda {@user_email.present?}, |
||||||
|
:message => "with given email was not found" |
||||||
|
} |
||||||
|
validate do |
||||||
|
errors[:user] = 'cannot be yourself' if user_id == domain.user_id |
||||||
|
end |
||||||
|
|
||||||
|
def user_email |
||||||
|
@user_email || user.try(:email) |
||||||
|
end |
||||||
|
|
||||||
|
def user_email=(email) |
||||||
|
@user_email = email |
||||||
|
self.user = User.find_by_email(email) |
||||||
|
end |
||||||
|
|
||||||
|
def to_label |
||||||
|
user.try(:email) || @user_email || '-' |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,114 @@ |
|||||||
|
# https://gist.github.com/1523940 |
||||||
|
module CanCan |
||||||
|
|
||||||
|
module ModelAdapters |
||||||
|
class ActiveRecordAdapter < AbstractAdapter |
||||||
|
|
||||||
|
def self.override_condition_matching?(subject, name, value) |
||||||
|
name.kind_of?(Squeel::Nodes::Predicate) if defined? Squeel |
||||||
|
end |
||||||
|
|
||||||
|
def self.matches_condition?(subject, name, value) |
||||||
|
subject_value = subject.send(name.expr) |
||||||
|
method_name = name.method_name.to_s |
||||||
|
if method_name.ends_with? "_any" |
||||||
|
value.any? { |v| squeel_match? subject_value, method_name.sub("_any", ""), v } |
||||||
|
elsif method_name.ends_with? "_all" |
||||||
|
value.all? { |v| squeel_match? subject_value, method_name.sub("_all", ""), v } |
||||||
|
else |
||||||
|
squeel_match? subject_value, name.method_name, value |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def self.squeel_match?(subject_value, method, value) |
||||||
|
case method.to_sym |
||||||
|
when :eq then subject_value == value |
||||||
|
when :not_eq then subject_value != value |
||||||
|
when :in then value.include?(subject_value) |
||||||
|
when :not_in then !value.include?(subject_value) |
||||||
|
when :lt then subject_value < value |
||||||
|
when :lteq then subject_value <= value |
||||||
|
when :gt then subject_value > value |
||||||
|
when :gteq then subject_value >= value |
||||||
|
when :matches then subject_value =~ Regexp.new("^" + Regexp.escape(value).gsub("%", ".*") + "$", true) |
||||||
|
when :does_not_match then !squeel_match?(subject_value, :matches, value) |
||||||
|
else raise NotImplemented, "The #{method} Squeel condition is not supported." |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def tableized_conditions(conditions, model_class = @model_class) |
||||||
|
return conditions unless conditions.kind_of? Hash |
||||||
|
conditions.inject({}) do |result_hash, (name, value)| |
||||||
|
name_sym = case name |
||||||
|
when Symbol then name |
||||||
|
when Squeel::Nodes::Join then name._name |
||||||
|
when Squeel::Nodes::Predicate then name.expr |
||||||
|
else raise name |
||||||
|
end |
||||||
|
if value.kind_of? Hash |
||||||
|
reflection = model_class.reflect_on_association(name_sym) |
||||||
|
association_class = reflection.class_name.constantize |
||||||
|
name_sym = reflection.table_name.to_sym |
||||||
|
value = tableized_conditions(value, association_class) |
||||||
|
end |
||||||
|
result_hash[name_sym] = value |
||||||
|
result_hash |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
# override to fix overwrites |
||||||
|
# do not write existing hashes using empty hashes |
||||||
|
def merge_joins(base, add) |
||||||
|
add.each do |name, nested| |
||||||
|
if base[name].is_a?(Hash) && nested.present? |
||||||
|
merge_joins(base[name], nested) |
||||||
|
elsif !base[name].is_a?(Hash) || nested.present? |
||||||
|
base[name] = nested |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
class Rule |
||||||
|
# allow Squeel |
||||||
|
def matches_conditions_hash?(subject, conditions = @conditions) |
||||||
|
if conditions.empty? |
||||||
|
true |
||||||
|
else |
||||||
|
if model_adapter(subject).override_conditions_hash_matching? subject, conditions |
||||||
|
model_adapter(subject).matches_conditions_hash? subject, conditions |
||||||
|
else |
||||||
|
conditions.all? do |name, value| |
||||||
|
if model_adapter(subject).override_condition_matching? subject, name, value |
||||||
|
model_adapter(subject).matches_condition? subject, name, value |
||||||
|
else |
||||||
|
method_name = case name |
||||||
|
when Symbol then name |
||||||
|
when Squeel::Nodes::Join then name._name |
||||||
|
when Squeel::Nodes::Predicate then name.expr |
||||||
|
else raise name |
||||||
|
end |
||||||
|
attribute = subject.send(method_name) |
||||||
|
if value.kind_of?(Hash) |
||||||
|
if attribute.kind_of? Array |
||||||
|
attribute.any? { |element| matches_conditions_hash? element, value } |
||||||
|
else |
||||||
|
!attribute.nil? && matches_conditions_hash?(attribute, value) |
||||||
|
end |
||||||
|
elsif value.kind_of?(Array) || value.kind_of?(Range) |
||||||
|
value.include? attribute |
||||||
|
else |
||||||
|
attribute == value |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
Squeel.configure do |config| |
||||||
|
# To load hash extensions (to allow for AND (&), OR (|), and NOT (-) against |
||||||
|
# hashes of conditions) |
||||||
|
config.load_core_extensions :hash |
||||||
|
|
||||||
|
# To load symbol extensions (for a subset of the old MetaWhere functionality, |
||||||
|
# via ARel predicate methods on Symbols: :name.matches, etc) |
||||||
|
# config.load_core_extensions :symbol |
||||||
|
|
||||||
|
# To load both hash and symbol extensions |
||||||
|
config.load_core_extensions :hash, :symbol |
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
class CreatePermissions < ActiveRecord::Migration |
||||||
|
def change |
||||||
|
create_table :permissions do |t| |
||||||
|
t.references :domain # the domain to whom permission is being given |
||||||
|
t.references :user # the user newly permitted to manage the domain |
||||||
|
|
||||||
|
t.timestamps |
||||||
|
end |
||||||
|
add_index :permissions, :domain_id |
||||||
|
add_index :permissions, :user_id |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,15 @@ |
|||||||
|
class AddNameReversedToDomains < ActiveRecord::Migration |
||||||
|
def up |
||||||
|
# used for "%" search indexing in an ancestry fashion (materialized path pattern) |
||||||
|
# http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html |
||||||
|
add_column :domains, :name_reversed, :string, :limit => 255 |
||||||
|
execute "UPDATE domains SET name_reversed = REVERSE(name)" |
||||||
|
change_column :domains, :name_reversed, :string, :limit => 255, :null => false |
||||||
|
add_index :domains, :name_reversed |
||||||
|
end |
||||||
|
|
||||||
|
def down |
||||||
|
remove_index :domains, :column => :name_reversed |
||||||
|
remove_column :domains, :name_reversed |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,31 @@ |
|||||||
|
class AddUserstampsToModels < ActiveRecord::Migration |
||||||
|
def change |
||||||
|
add_column :users, :created_by_id, :integer |
||||||
|
add_column :users, :updated_by_id, :integer |
||||||
|
execute "UPDATE users SET created_by_id = id, updated_by_id = id" |
||||||
|
|
||||||
|
add_column :domains, :created_by_id, :integer |
||||||
|
add_column :domains, :updated_by_id, :integer |
||||||
|
execute "UPDATE domains SET created_by_id = user_id, updated_by_id = user_id" |
||||||
|
|
||||||
|
add_column :records, :created_by_id, :integer |
||||||
|
add_column :records, :updated_by_id, :integer |
||||||
|
execute <<-SQL |
||||||
|
UPDATE records |
||||||
|
LEFT JOIN domains ON records.domain_id = domains.id |
||||||
|
SET |
||||||
|
records.created_by_id = IFNULL(records.user_id, domains.user_id), |
||||||
|
records.updated_by_id = IFNULL(records.user_id, domains.user_id) |
||||||
|
SQL |
||||||
|
|
||||||
|
add_column :permissions, :created_by_id, :integer |
||||||
|
add_column :permissions, :updated_by_id, :integer |
||||||
|
execute <<-SQL |
||||||
|
UPDATE permissions |
||||||
|
LEFT JOIN domains ON permissions.domain_id = domains.id |
||||||
|
SET |
||||||
|
permissions.created_by_id = domains.user_id, |
||||||
|
permissions.updated_by_id = domains.user_id |
||||||
|
SQL |
||||||
|
end |
||||||
|
end |
@ -1,5 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe DashboardController do |
|
||||||
|
|
||||||
end |
|
@ -1,5 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe PagesController do |
|
||||||
|
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the AaaasHelper. For example: |
|
||||||
# |
|
||||||
# describe AaaasHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe AaaasHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the AsHelper. For example: |
|
||||||
# |
|
||||||
# describe AsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe AsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the CnamesHelper. For example: |
|
||||||
# |
|
||||||
# describe CnamesHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe CnamesHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the DashboardHelper. For example: |
|
||||||
# |
|
||||||
# describe DashboardHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe DashboardHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the DomainsHelper. For example: |
|
||||||
# |
|
||||||
# describe DomainsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe DomainsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the HostsHelper. For example: |
|
||||||
# |
|
||||||
# describe HostsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe HostsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the MxesHelper. For example: |
|
||||||
# |
|
||||||
# describe MxesHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe MxesHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the NsHelper. For example: |
|
||||||
# |
|
||||||
# describe NsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe NsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the PagesHelper. For example: |
|
||||||
# |
|
||||||
# describe PagesHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe PagesHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the RecordsHelper. For example: |
|
||||||
# |
|
||||||
# describe RecordsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe RecordsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the SoAsHelper. For example: |
|
||||||
# |
|
||||||
# describe SoAsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe SoasHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the SrvsHelper. For example: |
|
||||||
# |
|
||||||
# describe SrvsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe SrvsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes |
|
||||||
# the TxtsHelper. For example: |
|
||||||
# |
|
||||||
# describe TxtsHelper do |
|
||||||
# describe "string concat" do |
|
||||||
# it "concats two strings with spaces" do |
|
||||||
# helper.concat_strings("this","that").should == "this that" |
|
||||||
# end |
|
||||||
# end |
|
||||||
# end |
|
||||||
describe TxtsHelper do |
|
||||||
pending "add some examples to (or delete) #{__FILE__}" |
|
||||||
end |
|
@ -0,0 +1,15 @@ |
|||||||
|
require 'spec_helper' |
||||||
|
|
||||||
|
describe Permission do |
||||||
|
include_context "data" |
||||||
|
|
||||||
|
it "validates selfness" do |
||||||
|
permission.user_id = permission.domain.user_id |
||||||
|
permission.should have(1).error_on(:user) |
||||||
|
end |
||||||
|
|
||||||
|
it "validates unexsisting email" do |
||||||
|
permission.user_email = "does.not@exist.in.db" |
||||||
|
permission.should have(1).error_on(:user) |
||||||
|
end |
||||||
|
end |
@ -1,5 +1,8 @@ |
|||||||
require 'spec_helper' |
require 'spec_helper' |
||||||
|
|
||||||
describe User do |
describe User do |
||||||
pending "add some examples to (or delete) #{__FILE__}" |
include_context "data" |
||||||
|
it "is valid" do |
||||||
|
user.should be_valid |
||||||
|
end |
||||||
end |
end |
||||||
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Aaaas" do |
|
||||||
describe "GET /aaaas" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get aaaas_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "As" do |
|
||||||
describe "GET /as" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get as_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Cnames" do |
|
||||||
describe "GET /cnames" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get cnames_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Domains" do |
|
||||||
describe "GET /domains" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get domains_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Hosts" do |
|
||||||
describe "GET /hosts" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get hosts_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Mxes" do |
|
||||||
describe "GET /mxes" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get mxes_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Ns" do |
|
||||||
describe "GET /ns" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get ns_index_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Records" do |
|
||||||
describe "GET /records" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get records_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Soas" do |
|
||||||
describe "GET /soas" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get soas_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Srvs" do |
|
||||||
describe "GET /srvs" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get srvs_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "Txts" do |
|
||||||
describe "GET /txts" do |
|
||||||
it "works! (now write some real specs)" do |
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
|
||||||
get txts_path |
|
||||||
response.status.should be(200) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,35 @@ |
|||||||
|
require "spec_helper" |
||||||
|
|
||||||
|
describe PermissionsController do |
||||||
|
describe "routing" do |
||||||
|
|
||||||
|
it "routes to #index" do |
||||||
|
get("/permissions").should route_to("permissions#index") |
||||||
|
end |
||||||
|
|
||||||
|
it "routes to #new" do |
||||||
|
get("/permissions/new").should route_to("permissions#new") |
||||||
|
end |
||||||
|
|
||||||
|
it "routes to #show" do |
||||||
|
get("/permissions/1").should route_to("permissions#show", :id => "1") |
||||||
|
end |
||||||
|
|
||||||
|
it "routes to #edit" do |
||||||
|
get("/permissions/1/edit").should route_to("permissions#edit", :id => "1") |
||||||
|
end |
||||||
|
|
||||||
|
it "routes to #create" do |
||||||
|
post("/permissions").should route_to("permissions#create") |
||||||
|
end |
||||||
|
|
||||||
|
it "routes to #update" do |
||||||
|
put("/permissions/1").should route_to("permissions#update", :id => "1") |
||||||
|
end |
||||||
|
|
||||||
|
it "routes to #destroy" do |
||||||
|
delete("/permissions/1").should route_to("permissions#destroy", :id => "1") |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
@ -1,40 +1,35 @@ |
|||||||
shared_context "data" do |
shared_context "data" do |
||||||
|
let(:admin){create(:user)} # admin is a user that owns host domains |
||||||
|
let(:user){create(:user)} # a regular user |
||||||
|
let(:user2){create(:user)} |
||||||
|
let(:user3){create(:user)} |
||||||
|
|
||||||
let(:user){create(:user)} |
def make_domain(options) |
||||||
let(:ability){Ability.new(:user => user)} |
domain = build(:domain, options) |
||||||
let(:other_user){create(:user)} |
|
||||||
let(:other_user_ability){Ability.new(:user => other_user)} |
|
||||||
|
|
||||||
let(:domain){ |
|
||||||
domain = build(:domain, :user => user) |
|
||||||
domain.setup(FactoryGirl.generate(:email)) |
domain.setup(FactoryGirl.generate(:email)) |
||||||
domain.save! |
domain.save! |
||||||
domain.soa_record.update_serial! |
domain.soa_record.update_serial! |
||||||
domain |
domain |
||||||
} |
end |
||||||
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 |
# user's domains |
||||||
let(:admin){ |
let(:domain){make_domain(:user => user)} |
||||||
admin_user = create(:user, |
let(:subdomain){make_domain(:name => "sub.#{domain.name}", :user => user)} |
||||||
:first_name => 'admin', |
let(:subsubdomain){make_domain(:name => "sub.#{subdomain.name}", :user => user)} |
||||||
: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){ |
# third user's domains |
||||||
domain = build(:domain, :user => admin, :name => Settings.host_domains.first) |
let(:domain3){make_domain(:user => user3)} |
||||||
domain.setup(FactoryGirl.generate(:email)) |
let(:subdomain3){make_domain(:name => "sub.#{domain.name}", :user => user3)} |
||||||
domain.save! |
let(:subsubdomain3){make_domain(:name => "sub.#{subdomain.name}", :user => user3)} |
||||||
domain.soa_record.update_serial! |
|
||||||
domain |
# admin's host domain (like entrydns.org) |
||||||
} |
let(:host_domain){make_domain(:user => admin, :name => Settings.host_domains.first)} |
||||||
|
|
||||||
|
let(:a_record){create(:a, :content => '127.0.0.1', :domain => domain)} |
||||||
|
let(:soa_record){domain.soa_record} |
||||||
let(:host_a_record){create(:a, :content => '127.0.0.1', :domain => host_domain, :user => user)} |
let(:host_a_record){create(:a, :content => '127.0.0.1', :domain => host_domain, :user => user)} |
||||||
|
|
||||||
|
let(:permission){create(:permission, :domain => domain, :user => user2)} |
||||||
|
let(:permission3){create(:permission, :domain => domain3, :user => user)} |
||||||
|
|
||||||
end |
end |
||||||
|
@ -0,0 +1,40 @@ |
|||||||
|
shared_examples_for "wiring controller" do |
||||||
|
context "wiring" do |
||||||
|
include_context "data" |
||||||
|
let(:record){Record.new} |
||||||
|
|
||||||
|
context "on owned domain" do |
||||||
|
before do |
||||||
|
sign_in user |
||||||
|
@controller.stub(:nested_parent_record => domain) |
||||||
|
end |
||||||
|
|
||||||
|
it "#new_model is wired" do |
||||||
|
@controller.send(:new_model).user.should == domain.user |
||||||
|
end |
||||||
|
|
||||||
|
it "#before_create_save wires" do |
||||||
|
@controller.send(:before_create_save, record) |
||||||
|
record.user.should == domain.user |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "on permitted domain" do |
||||||
|
before do |
||||||
|
sign_in user2 |
||||||
|
permission # touch to ensure creation |
||||||
|
@controller.stub(:nested_parent_record => domain) |
||||||
|
end |
||||||
|
|
||||||
|
it "#new_model is wired" do |
||||||
|
@controller.send(:new_model).user.should == domain.user |
||||||
|
end |
||||||
|
|
||||||
|
it "#before_create_save wires" do |
||||||
|
@controller.send(:before_create_save, record) |
||||||
|
record.user.should == domain.user |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "aaaas/edit.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@aaaa = assign(:aaaa, stub_model(Aaaa)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders the edit aaaa form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => aaaas_path(@aaaa), :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,14 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "aaaas/index.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:aaaas, [ |
|
||||||
stub_model(Aaaa), |
|
||||||
stub_model(Aaaa) |
|
||||||
]) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders a list of aaaas" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "aaaas/new.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:aaaa, stub_model(Aaaa).as_new_record) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders new aaaa form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => aaaas_path, :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "aaaas/show.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@aaaa = assign(:aaaa, stub_model(Aaaa)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders attributes in <p>" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "as/edit.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@a = assign(:a, stub_model(A)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders the edit a form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => as_path(@a), :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,14 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "as/index.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:as, [ |
|
||||||
stub_model(A), |
|
||||||
stub_model(A) |
|
||||||
]) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders a list of as" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "as/new.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:a, stub_model(A).as_new_record) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders new a form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => as_path, :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "as/show.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@a = assign(:a, stub_model(A)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders attributes in <p>" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "cnames/edit.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@cname = assign(:cname, stub_model(Cname)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders the edit cname form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => cnames_path(@cname), :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,14 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "cnames/index.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:cnames, [ |
|
||||||
stub_model(Cname), |
|
||||||
stub_model(Cname) |
|
||||||
]) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders a list of cnames" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "cnames/new.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:cname, stub_model(Cname).as_new_record) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders new cname form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => cnames_path, :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "cnames/show.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@cname = assign(:cname, stub_model(Cname)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders attributes in <p>" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "domains/edit.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@domain = assign(:domain, stub_model(Domain)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders the edit domain form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => domains_path(@domain), :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,14 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "domains/index.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:domains, [ |
|
||||||
stub_model(Domain), |
|
||||||
stub_model(Domain) |
|
||||||
]) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders a list of domains" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "domains/new.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:domain, stub_model(Domain).as_new_record) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders new domain form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => domains_path, :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "domains/show.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@domain = assign(:domain, stub_model(Domain)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders attributes in <p>" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "hosts/edit.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@host = assign(:host, stub_model(Host)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders the edit host form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => hosts_path(@host), :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,14 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "hosts/index.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:hosts, [ |
|
||||||
stub_model(Host), |
|
||||||
stub_model(Host) |
|
||||||
]) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders a list of hosts" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
@ -1,15 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "hosts/new.html.erb" do |
|
||||||
before(:each) do |
|
||||||
assign(:host, stub_model(Host).as_new_record) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders new host form" do |
|
||||||
render |
|
||||||
|
|
||||||
# Run the generator again with the --webrat flag if you want to use webrat matchers |
|
||||||
assert_select "form", :action => hosts_path, :method => "post" do |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,11 +0,0 @@ |
|||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe "hosts/show.html.erb" do |
|
||||||
before(:each) do |
|
||||||
@host = assign(:host, stub_model(Host)) |
|
||||||
end |
|
||||||
|
|
||||||
it "renders attributes in <p>" do |
|
||||||
render |
|
||||||
end |
|
||||||
end |
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue