Merge with sub_roles
This commit is contained in:
1 parent
fc591ee308
commit
62aaf79491
308 files changed
+2844
-17841
No files matched your search
@@ -1,47 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe DesignController do
|
||||
|
||||
describe "GET 'index'" do
|
||||
it "should be successful" do
|
||||
get 'index'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'new'" do
|
||||
it "should be successful" do
|
||||
get 'new'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'update'" do
|
||||
it "should be successful" do
|
||||
get 'update'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'edit'" do
|
||||
it "should be successful" do
|
||||
get 'edit'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'destroy'" do
|
||||
it "should be successful" do
|
||||
get 'destroy'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'create'" do
|
||||
it "should be successful" do
|
||||
get 'create'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,15 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the DesignHelper. For example:
|
||||
#
|
||||
# describe DesignHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# helper.concat_strings("this","that").should == "this that"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe DesignHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -0,0 +1,137 @@
|
||||
require 'spec_helper'
|
||||
require 'ruby-debug'
|
||||
|
||||
|
||||
describe AppAuth do
|
||||
|
||||
before do
|
||||
User.all.destroy
|
||||
UserRole.all.destroy
|
||||
AppAuth.all.destroy
|
||||
ModuleApp.all.destroy
|
||||
|
||||
#Create some fixtures of Main Role
|
||||
main_role_key = ["Stud","Teacher","Staff"]
|
||||
@new_main_role_list = main_role_key.each do |role|
|
||||
new_role = UserRole.new :key => role
|
||||
|
||||
new_role.save
|
||||
end
|
||||
#Create some users of User
|
||||
user_emails = ["a_good_stud","a_bad_stud","a_teacher","a_staff"]
|
||||
user_emails.each do |user_email|
|
||||
email=user_email+"@rulingcom.com"
|
||||
new_user = User.new :email=> email
|
||||
new_user.save
|
||||
end
|
||||
|
||||
@stud_MRK = UserRole.first(conditions:{key:"Stud"})
|
||||
@teacher_MRK = UserRole.first(conditions:{key:"Teacher"})
|
||||
@staff_MRK = UserRole.first(conditions:{key:"Staff"})
|
||||
|
||||
@good_stu = User.first(conditions:{email:"a_good_stud@rulingcom.com"})
|
||||
@bad_stu = User.first(conditions:{email:"a_bad_stud@rulingcom.com"})
|
||||
@teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"})
|
||||
@staff = User.first(conditions:{email:"a_staff@rulingcom.com"})
|
||||
|
||||
#setting Roles for users
|
||||
@good_stu.user_role = @stud_MRK
|
||||
@bad_stu.user_role = @stud_MRK
|
||||
@teacher.user_role = @teacher_MRK
|
||||
@staff.user_role = @staff_MRK
|
||||
|
||||
@good_stu.save!
|
||||
@bad_stu.save!
|
||||
@teacher.save!
|
||||
@staff.save!
|
||||
|
||||
end
|
||||
describe "Testing basic structure" do
|
||||
before do
|
||||
@app_auth = AppAuth.new()
|
||||
#all stud has access right
|
||||
@app_auth.user_roles << @stud_MRK
|
||||
|
||||
#a_bad_stud add to block to app_auth
|
||||
@app_auth.blocked_users << @bad_stu
|
||||
|
||||
#all teacher has access right
|
||||
@app_auth.user_roles << @teacher_MRK
|
||||
|
||||
@app_auth.privilege_users << @staff
|
||||
@app_auth.save!
|
||||
end
|
||||
context "Should just initialize all obj that is needed" do
|
||||
|
||||
it "Testing @app_auth init result" do
|
||||
@app_auth.user_roles.should have(2).item
|
||||
end
|
||||
|
||||
it "@app_auth should have UserRoles: Stud , Teacher " do
|
||||
key_ary = @app_auth.user_roles.collect do |role|
|
||||
role.key
|
||||
end
|
||||
key_ary.should == ["Stud","Teacher"]
|
||||
end
|
||||
|
||||
it "@app_auth should have one Privialage user which is belongs to Staff" do
|
||||
p_user_ary = @app_auth.privilege_users.collect do |p_user|
|
||||
p_user.user_role.key
|
||||
end
|
||||
p_user_ary.should include("Staff")
|
||||
end
|
||||
|
||||
it "@app_auth should have one student listed at blocklist" do
|
||||
@bad_stu = User.first(conditions:{email:"a_bad_stud@rulingcom.com"})
|
||||
@app_auth.blocked_users.should have(1).item
|
||||
@app_auth.blocked_users.should include(@bad_stu)
|
||||
end
|
||||
|
||||
it "[Development #1]-1.Authorizing roles: roles + blocklist" do
|
||||
@good_stu = User.first(conditions:{email:"a_good_stud@rulingcom.com"})
|
||||
@teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"})
|
||||
@staff = User.first(conditions:{email:"a_staff@rulingcom.com"})
|
||||
ary = [@good_stu,@teacher,@staff]
|
||||
@app_auth.auth_users_after_block_list.should == ary
|
||||
end
|
||||
|
||||
it "[Development #1]-2.Authorizing single users: list of users [new_user1~2]" do
|
||||
user_emails = ["new_user1","new_user2","new_user3","new_user4"]
|
||||
user_emails.each do |user_email|
|
||||
email=user_email+"@rulingcom.com"
|
||||
new_user = User.new :email=> email
|
||||
new_user.save
|
||||
end
|
||||
user1= User.first(conditions:{email:"new_user1@rulingcom.com"})
|
||||
user2= User.first(conditions:{email:"new_user2@rulingcom.com"})
|
||||
user3= User.first(conditions:{email:"new_user3@rulingcom.com"})
|
||||
user4= User.first(conditions:{email:"new_user4@rulingcom.com"})
|
||||
|
||||
@app_auth.privilege_users << user1
|
||||
@app_auth.privilege_users << user2
|
||||
|
||||
@app_auth.auth_users_after_block_list.should include(user1,user2)
|
||||
@app_auth.auth_users_after_block_list.should_not include(user3,user4)
|
||||
|
||||
end
|
||||
|
||||
it "[Development #1]-3.Authorizing roles and single users: roles + blocklist + list of users" do
|
||||
@app_auth.auth_users.should have(4).item
|
||||
end
|
||||
|
||||
it "[Development #1]-4.Authorizing all: blocklist" do
|
||||
@bad_stu = User.first(conditions:{email:"a_bad_stud@rulingcom.com"})
|
||||
@new_app_auth = (AppAuth.new :all => true)
|
||||
@new_app_auth.blocked_users << @bad_stu
|
||||
|
||||
@new_app_auth.auth_users.should == User.all.entries
|
||||
@new_app_auth.auth_users_after_block_list.should_not include(@bad_stu)
|
||||
@new_app_auth.save!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,81 @@
|
||||
require 'spec_helper'
|
||||
require 'ruby-debug'
|
||||
|
||||
describe AppAuth do
|
||||
|
||||
before(:all) do
|
||||
@app_ary = [
|
||||
{"name" => "G_app_1" , "all" => false,"blockusers" => ["a_bad_stud@rulingcom.com"]},
|
||||
{"name" => "G_app_2" , "all" => true,"blockusers" => ["a_bad_stud@rulingcom.com"]},
|
||||
{"name" => "G_app_3_for_bad" , "all" => true,"blockusers" => []}
|
||||
]
|
||||
|
||||
@app_ary.each do |t|
|
||||
a = ModuleApp.new :title => t["name"]
|
||||
blocked_users = t["blockusers"].collect do |b_user|
|
||||
User.first(conditions:{email:b_user})
|
||||
end
|
||||
a.create_app_auth :all=> t["all"],:blocked_users => blocked_users
|
||||
a.save!
|
||||
end
|
||||
@good_stud_become_bad = User.first(conditions:{email:"a_good_stud@rulingcom.com"})
|
||||
@bad_stud_become_good = User.first(conditions:{email:"a_bad_stud@rulingcom.com"})
|
||||
@g_app_1 = ModuleApp.first(conditions:{title:"G_app_1"})
|
||||
@g_app_2 = ModuleApp.first(conditions:{title:"G_app_2"})
|
||||
@g_app_3 = ModuleApp.first(conditions:{title:"G_app_3_for_bad"})
|
||||
end
|
||||
|
||||
describe "[Init status check]" do
|
||||
it "bad_stud_become_good status " do
|
||||
@bad_stud_become_good.avb_apps.should_not include @g_app_1.app_auth
|
||||
@bad_stud_become_good.avb_apps.should_not include @g_app_2.app_auth
|
||||
@bad_stud_become_good.avb_apps.should include @g_app_3.app_auth
|
||||
end
|
||||
|
||||
it "good_stud_become_bad status " do
|
||||
@good_stud_become_bad.avb_apps.should_not include @g_app_1.app_auth
|
||||
@good_stud_become_bad.avb_apps.should include @g_app_2.app_auth
|
||||
@good_stud_become_bad.avb_apps.should include @g_app_3.app_auth
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_user_to_black_list sutd" do
|
||||
it "When good stud is blocked with app1 and app2" do
|
||||
@g_app_1.app_auth.add_user_to_black_list @good_stud_become_bad
|
||||
@g_app_2.app_auth.add_user_to_black_list @good_stud_become_bad
|
||||
@good_stud_become_bad.avb_apps.should_not include @g_app_1.app_auth
|
||||
@good_stud_become_bad.avb_apps.should_not include @g_app_2.app_auth
|
||||
end
|
||||
end
|
||||
|
||||
describe ".remove_user_from_black_list sutd" do
|
||||
it "When bad stud is authed with app1 and app2" do
|
||||
@g_app_1.app_auth.remove_user_from_black_list @bad_stud_become_good
|
||||
@g_app_2.app_auth.remove_user_from_black_list @bad_stud_become_good
|
||||
#@bad_stud_become_good.avb_apps.should include @g_app_1.app_auth
|
||||
@bad_stud_become_good.avb_apps.should include @g_app_2.app_auth
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_user_to_privilege_list sutd" do
|
||||
it "When bad stud is auth for one more app" do
|
||||
@bad_stud_become_good.avb_apps.should_not include @g_app_1.app_auth #shouldn't have at first time since app1 is not sat for all
|
||||
@g_app_1.app_auth.add_user_to_privilege_list @bad_stud_become_good #change status
|
||||
@bad_stud_become_good.avb_apps.should include @g_app_1.app_auth #check
|
||||
end
|
||||
end
|
||||
|
||||
describe ".remove_user_from_privilege_list sutd" do
|
||||
it "admin mistake. remove user from privilege list" do
|
||||
@g_app_1.app_auth.remove_user_from_privilege_list @bad_stud_become_good
|
||||
@bad_stud_become_good.avb_apps.should_not include @g_app_1.app_auth
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@app_ary.each do |item|
|
||||
ModuleApp.first(conditions: {title: item["name"]}).destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Design do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -0,0 +1,113 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Role do
|
||||
before do
|
||||
@role = Role.create(:key => 'teacher',
|
||||
:i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'},
|
||||
:sub_roles => [{:key => 'undergrad',
|
||||
:i18n_variable => {:key => 'yeah', :en => 'Yeah', :zh_tw => 'Yeah', :document_class => 'Role'},
|
||||
:attribute_fields => [{:key => 'department'},
|
||||
{:key => 'room'}]},
|
||||
{:key => 'master',
|
||||
:attribute_fields => [{:key => 'department'}]}])
|
||||
end
|
||||
describe 'New role' do
|
||||
describe '#Role' do
|
||||
it 'should have :built_in false' do
|
||||
@role.built_in.should be false
|
||||
end
|
||||
it 'should have :disabled false' do
|
||||
@role.disabled.should be false
|
||||
end
|
||||
it 'should have a i18n_variable' do
|
||||
@role.i18n_variable.should be_an_instance_of I18nVariable
|
||||
end
|
||||
it 'should create sub_roles' do
|
||||
@role.should have(2).sub_roles
|
||||
end
|
||||
it 'should create attribute_fields' do
|
||||
@role.sub_roles[1].should have(1).attribute_fields
|
||||
end
|
||||
end
|
||||
describe '#SubRole' do
|
||||
it 'should have :built_in false' do
|
||||
@role.sub_roles[0].built_in.should be false
|
||||
end
|
||||
it 'should have :disabled false' do
|
||||
@role.sub_roles[0].disabled.should be false
|
||||
end
|
||||
it 'should have a i18n_variable' do
|
||||
@role.sub_roles[0].i18n_variable.should be_an_instance_of I18nVariable
|
||||
end
|
||||
end
|
||||
describe '#AttributeField' do
|
||||
it 'should have :built_in false' do
|
||||
@role.sub_roles[0].attribute_fields[0].built_in.should be false
|
||||
end
|
||||
it 'should have :disabled false' do
|
||||
@role.sub_roles[0].attribute_fields[0].disabled.should be false
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'Edit role' do
|
||||
describe '#Role' do
|
||||
before do
|
||||
@role.update_attributes({:key => 'student', :i18n_variable => {:en => 'Student'},
|
||||
:sub_roles => [{:key => 'new',
|
||||
:attribute_fields => [{:key => 'bob'},
|
||||
{:key => 'great'}]},
|
||||
{:id => @role.sub_roles[0].id},
|
||||
{:id => @role.sub_roles[1].id}]})
|
||||
end
|
||||
it 'should not be the old :key' do
|
||||
@role.key.should_not == 'teacher'
|
||||
end
|
||||
it 'should be the new :key' do
|
||||
@role.key.should == 'student'
|
||||
end
|
||||
it 'should not be the old :i18n_variable[:en]' do
|
||||
@role.i18n_variable[:en].should_not == 'Teacher'
|
||||
end
|
||||
it 'should be the new :i18n_variable[:en]' do
|
||||
@role.i18n_variable[:en].should == 'Student'
|
||||
end
|
||||
it 'should have one more SubRole' do
|
||||
@role.should have(3).sub_roles
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'Destroy' do
|
||||
describe '#AttributeField' do
|
||||
before do
|
||||
@role.update_attributes(:key => 'teacher',
|
||||
:i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'},
|
||||
:sub_roles_attributes => {'0' => {:id => @role.sub_roles[0].id,
|
||||
:key => 'undergrad',
|
||||
:attribute_fields_attributes => {'0' => {:id => @role.sub_roles[0].attribute_fields[0].id,
|
||||
:key => 'department'},
|
||||
'1' => {:id => @role.sub_roles[0].attribute_fields[1].id,
|
||||
:key => 'room', :_destroy => true}}}})
|
||||
end
|
||||
it 'should have only one AttributeField for the first SubRole' do
|
||||
@role.sub_roles[0].should have(1).attribute_fields
|
||||
end
|
||||
end
|
||||
describe '#I18nVariable' do
|
||||
before do
|
||||
@role.update_attributes(:key => 'teacher',
|
||||
:i18n_variable_attributes => {:id => @role.i18n_variable.id, :key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role', :_destroy => true})
|
||||
end
|
||||
it 'should not have a I18nVariable' do
|
||||
@role.i18n_variable.should_not be_an_instance_of I18nVariable
|
||||
end
|
||||
end
|
||||
describe '#Role' do
|
||||
it 'should destroy the I18nVariable' do
|
||||
id = @role.i18n_variable.id
|
||||
@role.destroy
|
||||
lambda {I18nVariable.find(id)}.should raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
--colour
|
||||
--format progress
|
||||
--loadby mtime
|
||||
--reverse
|
||||
+53
-22
@@ -1,27 +1,58 @@
|
||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.expand_path("../../config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'rubygems'
|
||||
require 'spork'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
||||
Spork.prefork do
|
||||
# Loading more in this block will cause your tests to run faster. However,
|
||||
# if you change any configuration or code from libraries loaded here, you'll
|
||||
# need to restart spork for it take effect.
|
||||
|
||||
RSpec.configure do |config|
|
||||
# == Mock Framework
|
||||
#
|
||||
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
||||
#
|
||||
# config.mock_with :mocha
|
||||
# config.mock_with :flexmock
|
||||
# config.mock_with :rr
|
||||
config.mock_with :rspec
|
||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.expand_path("../../config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'rspec/autorun'
|
||||
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
RSpec.configure do |config|
|
||||
# == Mock Framework
|
||||
#
|
||||
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
||||
#
|
||||
# config.mock_with :mocha
|
||||
# config.mock_with :flexmock
|
||||
# config.mock_with :rr
|
||||
config.mock_with :rspec
|
||||
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
# config.use_transactional_fixtures = true
|
||||
|
||||
# If true, the base class of anonymous controllers will be inferred
|
||||
# automatically. This will be the default behavior in future versions of
|
||||
# rspec-rails.
|
||||
config.infer_base_class_for_anonymous_controllers = false
|
||||
end
|
||||
end
|
||||
|
||||
Spork.each_run do
|
||||
# This code will be run each time you run your specs.
|
||||
load "#{Rails.root}/config/routes.rb"
|
||||
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
|
||||
end
|
||||
|
||||
# --- Instructions ---
|
||||
# - Sort through your spec_helper file. Place as much environment loading
|
||||
# code that you don't normally modify during development in the
|
||||
# Spork.prefork block.
|
||||
# - Place the rest under Spork.each_run block
|
||||
# - Any code that is left outside of the blocks will be ran during preforking
|
||||
# and during each_run!
|
||||
# - These instructions should self-destruct in 10 seconds. If they don't,
|
||||
# feel free to delete them.
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "design/create.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "design/destroy.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "design/edit.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "design/index.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "design/new.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "design/update.html.erb" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in new issue
Block a user