\ No newline at end of file
+<% content_for :page_specific_javascript do -%>
+
+<% end -%>
diff --git a/app/views/admin/infos/_attribute_field.html.erb b/app/views/admin/infos/_attribute_field.html.erb
index 12ed7828..95d60268 100644
--- a/app/views/admin/infos/_attribute_field.html.erb
+++ b/app/views/admin/infos/_attribute_field.html.erb
@@ -1,3 +1,100 @@
-<%= f.fields_for :attribute_fields, attribute_field do |f| %>
- <%= render :partial => 'admin/attributes/attribute_field', :object => attribute_field, :locals => {:f => f} %>
-<% end %>
\ No newline at end of file
+
+ <% @site_valid_locales.each do |locale| %>
+ <% active = (locale == @site_valid_locales.first ? "active in" : "'") %>
+ <%= content_tag :div,:class=>"tab-pane fade #{active}",:id=>"#{name_to_id(field_name)}_#{locale}" do%>
+ <% value = values[locale.to_s] rescue nil%>
+ <%= text_field(field_name, locale,:value=>value,:placeholder=>t("langs.#{locale}")) %>
+ <% end %>
+ <% end %>
+
+
+ <% @site_valid_locales.each do |locale| %>
+ <% active = (locale == @site_valid_locales.first ? "active" : "'") %>
+ <%=content_tag :li,:class=>active do %>
+ <%= link_to t("langs.#{locale}"),"##{name_to_id(field_name)}_#{locale}",:data=>{:toggle=>"tab"}%>
+ <% end %>
+ <% end %>
+
+
+
+ <% end %>
\ No newline at end of file
diff --git a/app/views/admin/infos/add_attribute_field.js.erb b/app/views/admin/infos/add_attribute_field.js.erb
new file mode 100644
index 00000000..693835e5
--- /dev/null
+++ b/app/views/admin/infos/add_attribute_field.js.erb
@@ -0,0 +1,6 @@
+$(".attributes").append('<%= escape_javascript(render :partial=>"attribute_field",:locals=>{:attribute_field=>@attribute_field,:attribute_field_counter=>@attribute_field_counter} )%>');
+ $(".dataType").change(function () {
+ $(this).parents("legend").next("div").find("div[class^='type']").addClass("hide");
+ $(this).parents("legend").next("div").find("."+$(this).find("option:selected").attr("ref")).removeClass("hide");
+
+ })
\ No newline at end of file
diff --git a/app/views/admin/users_new_interface/edit.html.erb b/app/views/admin/users_new_interface/edit.html.erb
index d61886df..1e169520 100644
--- a/app/views/admin/users_new_interface/edit.html.erb
+++ b/app/views/admin/users_new_interface/edit.html.erb
@@ -14,7 +14,7 @@
<% end -%>
-<%= content_tag :div,:class=>"user-role site-map" do%>
+<%= content_tag :div,:class=>"user-role site-map role-block" do%>
<%= form_for @user, :url => admin_users_new_interface_path(@user), :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
diff --git a/config/list.yml b/config/list.yml
index b0cf253f..ebfff364 100644
--- a/config/list.yml
+++ b/config/list.yml
@@ -9,21 +9,27 @@ markups:
text_field:
muti_lang_input_supprt: true
ext_support: true
+ panel: typeA
select:
muti_lang_input_supprt: false
ext_support: false
+ panel: typeB
date:
muti_lang_input_supprt: false
ext_support: false
+ panel: typeC
text_area:
muti_lang_input_supprt: true
ext_support: false
+ panel: typeD
radio_button:
muti_lang_input_supprt: false
ext_support: false
+ panel: typeE
checkbox:
muti_lang_input_supprt: false
ext_support: false
+ panel: typeE
# date_durnation:
# muti_lang_input_supprt: false
# ext_support: false
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 05715db9..822a12a8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -30,6 +30,14 @@ en:
langs:
zh_tw: Traditional Chinese
en: English
+ lists:
+ markups:
+ text_field: Text Field
+ select: Select
+ date: Date
+ text_area: Text Area
+ radio_button: Radio button
+ checkbox: Checkbox
login: Login
logout: Logout
no_: "No"
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index 3fa4029f..7ac9dd06 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -27,6 +27,14 @@ zh_tw:
langs:
zh_tw: 中文
en: 英文
+ lists:
+ markups:
+ text_field: 文字輸入框
+ select: 下拉選單
+ date: 日期
+ text_area: 文字輸入方塊
+ radio_button: 單選
+ checkbox: 多選
login: 登入
logout: 登出
nccu: 政大
@@ -83,8 +91,30 @@ zh_tw:
errors:
at_least_one: 必須至少有一個值
-
admin:
+ infos:
+ add_attribute_field: 新增
+ save: 儲存
+ initial: 起始值
+ markup: 輸入模式
+ item_name: 資料表名稱
+ name: 名稱
+ options: 選項
+ multilingual: 多語言輸入
+ add_more: 使用者可自行延伸欄位
+ add: 新增
+ placeholder: 輸入協助
+ type: 類型
+ placeholder: 提示內容
+ list: 自定選單
+ is_range: 是
+ not_range: 否
+ date:
+ claendar: 紀年法
+ range: 本欄為時間區段
+ format: 格式
+ tw_claendar: 民國
+ west_claendar: 西元
access:
denied:
app:
diff --git a/spec/helpers/attribute_fields_helper_spec.rb b/spec/helpers/attribute_fields_helper_spec.rb
new file mode 100644
index 00000000..84be036a
--- /dev/null
+++ b/spec/helpers/attribute_fields_helper_spec.rb
@@ -0,0 +1,78 @@
+#encoding: UTF-8
+require 'spec_helper'
+
+describe AttributeFieldsHelper do
+ describe "#attribute_field" do
+ context "In the HTML,there should always be 'value' tag in it's name"
+
+ before(:all) do
+ @user = User.where(email:'chris@rulingcom.com').first
+ end #end before
+ # binding.pry
+ LIST[:markups].each do |markup|
+ it "should have 'value' when it's #{markup[0]} (no locale)" do
+ title = "標題"
+ pre_set_markup_value = case markup[0]
+ when "select","checkbox","radio_button"
+ '{"1"=>{"en"=>"Male", "zh_tw"=>"男性"}, "2"=>{"en"=>"Female", "zh_tw"=>"女性"}, "3"=>{"en"=>"Not public", "zh_tw"=>"不公開"}}'
+ else
+ nil
+ end
+
+ attribute_field=AttributeField.find_or_create_by(key:'Test',markup: markup[0],markup_value: pre_set_markup_value,:title=>title)
+
+ html = attribute_field.block_helper(@user,1)
+
+ nodes = Nokogiri::HTML.fragment(html).search('*[@func="input_unit"]')
+
+ nodes.each do |input|
+ attri = input.attributes["name"]
+ attri = input.children().first.attributes["name"] if (markup[0] == 'checkbox' || markup[0] == 'radio_button' )
+ attri.to_s.should match /user\[.*attribute_values\]\[\d*\]\[value\].*/
+ # user[attribute_values][1][id]
+ # user[attribute_values][1][value][en]
+ end #end of input loop
+ end # end of it
+ end #end markups
+
+ LIST[:markups].each do |markup|
+ if markup[1]["muti_lang_input_supprt"]
+ [true,false].each do |locale_sat|
+ title = locale_sat ? {"en"=>"Title", "zh_tw"=>"標題"} : "標題"
+ it "should have 'value' when it's #{markup[0]} for locale => #{locale_sat}" do
+ pre_set_markup_value = case markup[0]
+ when "select","checkbox","radio_button"
+ '{"1"=>{"en"=>"Male", "zh_tw"=>"男性"}, "2"=>{"en"=>"Female", "zh_tw"=>"女性"}, "3"=>{"en"=>"Not public", "zh_tw"=>"不公開"}}'
+ else
+ nil
+ end
+ if (markup[0] == "text_field" || markup[0] == "text_area") && (locale_sat == false)
+ # binding.pry
+ end
+ attribute_field=AttributeField.find_or_create_by(key:'Test',markup: markup[0],markup_value: pre_set_markup_value,:title=>title,:locale => locale_sat)
+
+ html = attribute_field.block_helper(@user,1)
+
+ # p html
+ nodes = Nokogiri::HTML.fragment(html).search('*[@func="input_unit"]')
+ nodes.each do |input|
+ input.attributes["name"].to_s.should match /user\[.*attribute_values\]\[\d*\]\[value\].*/
+ # user[attribute_values][1][id]
+ # user[attribute_values][1][value][en]
+ end #end of input loop
+ nodes = Nokogiri::HTML.fragment(html).search('*[@func="field_label"]')
+
+ nodes.each do |input|
+ # p input.to_s
+ # binding.pry if
+
+ input.children.text.should match "標題"
+ end # end of field_label loop
+ end # end of it
+ end # end of T/F
+ end# end of if support
+ end #end markups
+
+
+ end
+end
\ No newline at end of file
diff --git a/spec/models/app_auth_basic.rb b/spec/models/app_auth_basic.rb
index 0f629119..0f8549b7 100644
--- a/spec/models/app_auth_basic.rb
+++ b/spec/models/app_auth_basic.rb
@@ -1,218 +1,218 @@
-require 'spec_helper'
-require 'ruby-debug'
+# require 'spec_helper'
+# require 'ruby-debug'
-describe AppAuth do
+# describe AppAuth do
- before do
- User.all.destroy
- Role.all.destroy
- SubRole.all.destroy
- AppAuth.all.destroy
- ModuleApp.all.destroy
+# before do
+# User.all.destroy
+# Role.all.destroy
+# SubRole.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 = Role.new :key => role
- new_role.save
- end
- #Create Some SubRoles
- sub_role_key = ["graduated_school","undergraduated_school","TA","Senior"]
- @new_main_role_list = sub_role_key.each do |role|
- new_role = SubRole.new :key => role
- new_role.save
- end
+# #Create some fixtures of Main Role
+# main_role_key = ["Stud","Teacher","Staff"]
+# @new_main_role_list = main_role_key.each do |role|
+# new_role = Role.new :key => role
+# new_role.save
+# end
+# #Create Some SubRoles
+# sub_role_key = ["graduated_school","undergraduated_school","TA","Senior"]
+# @new_main_role_list = sub_role_key.each do |role|
+# new_role = SubRole.new :key => role
+# new_role.save
+# end
- #Create some users of User
- user_emails = ["a_good_ug_stud_1","a_good_ug_stud_2","a_bad_ug_stud","a_good_g_stud","a_bad_g_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
- #MRK = Member Role Key SRK=Sub Role Key
- @stud_MRK = Role.first(conditions:{key:"Stud"})
- @teacher_MRK = Role.first(conditions:{key:"Teacher"})
- @staff_MRK = Role.first(conditions:{key:"Staff"})
+# #Create some users of User
+# user_emails = ["a_good_ug_stud_1","a_good_ug_stud_2","a_bad_ug_stud","a_good_g_stud","a_bad_g_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
+# #MRK = Member Role Key SRK=Sub Role Key
+# @stud_MRK = Role.first(conditions:{key:"Stud"})
+# @teacher_MRK = Role.first(conditions:{key:"Teacher"})
+# @staff_MRK = Role.first(conditions:{key:"Staff"})
- @graduated_SRK = SubRole.first(conditions:{key:"graduated_school"})
- @under_graduated_SRK = SubRole.first(conditions:{key:"undergraduated_school"})
- @ta_SRK = SubRole.first(conditions:{key:"TA"})
- @senior_SRK = SubRole.first(conditions:{key:"Senior"})
+# @graduated_SRK = SubRole.first(conditions:{key:"graduated_school"})
+# @under_graduated_SRK = SubRole.first(conditions:{key:"undergraduated_school"})
+# @ta_SRK = SubRole.first(conditions:{key:"TA"})
+# @senior_SRK = SubRole.first(conditions:{key:"Senior"})
- @stud_MRK.sub_roles += [@graduated,@under_graduated,@ta]
- @stud_MRK.save!
+# @stud_MRK.sub_roles += [@graduated,@under_graduated,@ta]
+# @stud_MRK.save!
- @teacher_MRK.sub_roles = [@senior]
- @teacher_MRK.save!
+# @teacher_MRK.sub_roles = [@senior]
+# @teacher_MRK.save!
- @good_ug_stu_1 = User.first(conditions:{email:"a_good_ug_stud_1@rulingcom.com"})
- @good_ug_stu_2 = User.first(conditions:{email:"a_good_ug_stud_2@rulingcom.com"})
- @bad_ug_stu = User.first(conditions:{email:"a_bad_ug_stud@rulingcom.com"})
+# @good_ug_stu_1 = User.first(conditions:{email:"a_good_ug_stud_1@rulingcom.com"})
+# @good_ug_stu_2 = User.first(conditions:{email:"a_good_ug_stud_2@rulingcom.com"})
+# @bad_ug_stu = User.first(conditions:{email:"a_bad_ug_stud@rulingcom.com"})
- @good_g_stu = User.first(conditions:{email:"a_good_g_stud@rulingcom.com"})
- @bad_g_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
- @teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"})
- @staff = User.first(conditions:{email:"a_staff@rulingcom.com"})
+# @good_g_stu = User.first(conditions:{email:"a_good_g_stud@rulingcom.com"})
+# @bad_g_stu = User.first(conditions:{email:"a_bad_g_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_g_stu.role = @stud_MRK
- @bad_g_stu.role = @stud_MRK
- @good_ug_stu_1.role = @stud_MRK
- @good_ug_stu_2.role = @stud_MRK
- @bad_ug_stu.role = @stud_MRK
+# #setting Roles for users
+# @good_g_stu.role = @stud_MRK
+# @bad_g_stu.role = @stud_MRK
+# @good_ug_stu_1.role = @stud_MRK
+# @good_ug_stu_2.role = @stud_MRK
+# @bad_ug_stu.role = @stud_MRK
- @good_g_stu.sub_roles = [@graduated_SRK,@ta_SRK]
- @bad_g_stu.sub_roles << @graduated_SRK
- @good_ug_stu_1.sub_roles << @under_graduated_SRK
- @good_ug_stu_2.sub_roles << @under_graduated_SRK
- @bad_ug_stu.sub_roles << @under_graduated_SRK
+# @good_g_stu.sub_roles = [@graduated_SRK,@ta_SRK]
+# @bad_g_stu.sub_roles << @graduated_SRK
+# @good_ug_stu_1.sub_roles << @under_graduated_SRK
+# @good_ug_stu_2.sub_roles << @under_graduated_SRK
+# @bad_ug_stu.sub_roles << @under_graduated_SRK
- @teacher.role = @teacher_MRK
- @staff.role = @staff_MRK
+# @teacher.role = @teacher_MRK
+# @staff.role = @staff_MRK
- @good_g_stu.save!
- @bad_g_stu.save!
- @good_ug_stu_1.save!
- @good_ug_stu_2.save!
- @bad_ug_stu.save!
+# @good_g_stu.save!
+# @bad_g_stu.save!
+# @good_ug_stu_1.save!
+# @good_ug_stu_2.save!
+# @bad_ug_stu.save!
- @teacher.save!
- @staff.save!
+# @teacher.save!
+# @staff.save!
- end
- describe "Starting a ClassBulletin Auth for teacher , staff and ta" do
- before do
- @bulletin_app_auth = AppAuth.new()
- #all teacher and staff has access right
- @bulletin_app_auth.roles = [@teacher_MRK,@staff_MRK]
- #all person with TA sub_role has access right
- @bulletin_app_auth.sub_roles << @ta_SRK
+# end
+# describe "Starting a ClassBulletin Auth for teacher , staff and ta" do
+# before do
+# @bulletin_app_auth = AppAuth.new()
+# #all teacher and staff has access right
+# @bulletin_app_auth.roles = [@teacher_MRK,@staff_MRK]
+# #all person with TA sub_role has access right
+# @bulletin_app_auth.sub_roles << @ta_SRK
- #a_bad_ug_stud add to block to bulletin_app_auth
- #@bulletin_app_auth.blocked_users << @bad_ug_stu
+# #a_bad_ug_stud add to block to bulletin_app_auth
+# #@bulletin_app_auth.blocked_users << @bad_ug_stu
- #all teacher has access right
- # @bulletin_app_auth.roles << @teacher_MRK
+# #all teacher has access right
+# # @bulletin_app_auth.roles << @teacher_MRK
- # @bulletin_app_auth.privilege_users << @staff
- @bulletin_app_auth.save!
- end
- context "Should just initialize all obj that is needed" do
+# # @bulletin_app_auth.privilege_users << @staff
+# @bulletin_app_auth.save!
+# end
+# context "Should just initialize all obj that is needed" do
- it "Testing @bulletin_app_auth init result" do
- @bulletin_app_auth.roles.should have(2).item #teacher staff
- @bulletin_app_auth.sub_roles.should have(1).item #ta
- end
+# it "Testing @bulletin_app_auth init result" do
+# @bulletin_app_auth.roles.should have(2).item #teacher staff
+# @bulletin_app_auth.sub_roles.should have(1).item #ta
+# end
- it "@bulletin_app_auth should have Roles: Staff , Teacher " do
- key_ary = @bulletin_app_auth.roles.collect do |role|
- role.key
- end
- key_ary.sort.should == ["Staff","Teacher"].sort
- end
+# it "@bulletin_app_auth should have Roles: Staff , Teacher " do
+# key_ary = @bulletin_app_auth.roles.collect do |role|
+# role.key
+# end
+# key_ary.sort.should == ["Staff","Teacher"].sort
+# end
- it "bulletin_app_auth should have 3 auth users" do
- user_ary = [@teacher,@staff,@good_g_stu]
- @bulletin_app_auth.auth_users.sort.should == user_ary.sort
- check_user_has_app user_ary
- end
+# it "bulletin_app_auth should have 3 auth users" do
+# user_ary = [@teacher,@staff,@good_g_stu]
+# @bulletin_app_auth.auth_users.sort.should == user_ary.sort
+# check_user_has_app user_ary
+# end
- it "Adding a undergraduate stud into app_auth by privilege list" do
- user_ary = [@teacher,@staff,@good_g_stu,@good_ug_stu_1]
- @bulletin_app_auth.add_user_to_privilege_list @good_ug_stu_1
- @bulletin_app_auth.auth_users.sort.should == user_ary.sort
- check_user_has_app user_ary
- end
+# it "Adding a undergraduate stud into app_auth by privilege list" do
+# user_ary = [@teacher,@staff,@good_g_stu,@good_ug_stu_1]
+# @bulletin_app_auth.add_user_to_privilege_list @good_ug_stu_1
+# @bulletin_app_auth.auth_users.sort.should == user_ary.sort
+# check_user_has_app user_ary
+# end
- it "Adding all graudated-stud into app_auth" do
- user_ary = [@teacher,@staff,@good_g_stu,@bad_g_stu]
- @bulletin_app_auth.add_sub_role @graduated_SRK
- @bulletin_app_auth.auth_users.sort.should == user_ary.sort
- check_user_has_app user_ary
- end
+# it "Adding all graudated-stud into app_auth" do
+# user_ary = [@teacher,@staff,@good_g_stu,@bad_g_stu]
+# @bulletin_app_auth.add_sub_role @graduated_SRK
+# @bulletin_app_auth.auth_users.sort.should == user_ary.sort
+# check_user_has_app user_ary
+# end
- it "Blocking bad-graduate student" do
- user_ary =[@teacher,@staff,@good_g_stu]
- @bulletin_app_auth.add_sub_role @graduated_SRK
- @bulletin_app_auth.add_user_to_black_list @bad_g_stu
- @bulletin_app_auth.auth_users_after_block_list.sort.should == user_ary.sort
- check_user_has_app user_ary
- end
+# it "Blocking bad-graduate student" do
+# user_ary =[@teacher,@staff,@good_g_stu]
+# @bulletin_app_auth.add_sub_role @graduated_SRK
+# @bulletin_app_auth.add_user_to_black_list @bad_g_stu
+# @bulletin_app_auth.auth_users_after_block_list.sort.should == user_ary.sort
+# check_user_has_app user_ary
+# end
- it "Removing all graudated-stud from app_auth" do
- user_ary =[@teacher,@staff,@good_g_stu]
- @bulletin_app_auth.add_sub_role @graduated_SRK
- @bulletin_app_auth.remove_sub_role @graduated_SRK
- @bulletin_app_auth.auth_users.sort.should == user_ary.sort
- check_user_has_app user_ary
- end
+# it "Removing all graudated-stud from app_auth" do
+# user_ary =[@teacher,@staff,@good_g_stu]
+# @bulletin_app_auth.add_sub_role @graduated_SRK
+# @bulletin_app_auth.remove_sub_role @graduated_SRK
+# @bulletin_app_auth.auth_users.sort.should == user_ary.sort
+# check_user_has_app user_ary
+# end
- # it "@bulletin_app_auth should have one Privialage user which is belongs to Staff" do
- # p_user_ary = @bulletin_app_auth.privilege_users.collect do |p_user|
- # p_user.roles.key
- # end
- # p_user_ary.should include("Staff")
- # end
+# # it "@bulletin_app_auth should have one Privialage user which is belongs to Staff" do
+# # p_user_ary = @bulletin_app_auth.privilege_users.collect do |p_user|
+# # p_user.roles.key
+# # end
+# # p_user_ary.should include("Staff")
+# # end
- # it "@bulletin_app_auth should have one student listed at blocklist" do
- # @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
- # @bulletin_app_auth.blocked_users.should have(1).item
- # @bulletin_app_auth.blocked_users.should include(@bad_stu)
- # end
+# # it "@bulletin_app_auth should have one student listed at blocklist" do
+# # @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
+# # @bulletin_app_auth.blocked_users.should have(1).item
+# # @bulletin_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_g_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]
- # @bulletin_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"})
- #
- # @bulletin_app_auth.privilege_users << user1
- # @bulletin_app_auth.privilege_users << user2
- #
- # @bulletin_app_auth.auth_users_after_block_list.should include(user1,user2)
- # @bulletin_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
- # @bulletin_app_auth.auth_users.should have(7).item
- # end
- #
- # it "[Development #1]-4.Authorizing all: blocklist" do
- # @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
- # @new_bulletin_app_auth = (AppAuth.new :all => true)
- # @new_bulletin_app_auth.blocked_users << @bad_stu
- #
- # @new_bulletin_app_auth.auth_users.should == User.all.entries
- # @new_bulletin_app_auth.auth_users_after_block_list.should_not include(@bad_stu)
- # @new_bulletin_app_auth.save!
- # end
- def check_user_has_app(user_ary)
- user_ary.each do |user|
- user.avb_apps.should include(@bulletin_app_auth)
- end
- end
- end
+# # it "[Development #1]-1.Authorizing roles: roles + blocklist" do
+# # @good_stu = User.first(conditions:{email:"a_good_g_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]
+# # @bulletin_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"})
+# #
+# # @bulletin_app_auth.privilege_users << user1
+# # @bulletin_app_auth.privilege_users << user2
+# #
+# # @bulletin_app_auth.auth_users_after_block_list.should include(user1,user2)
+# # @bulletin_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
+# # @bulletin_app_auth.auth_users.should have(7).item
+# # end
+# #
+# # it "[Development #1]-4.Authorizing all: blocklist" do
+# # @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
+# # @new_bulletin_app_auth = (AppAuth.new :all => true)
+# # @new_bulletin_app_auth.blocked_users << @bad_stu
+# #
+# # @new_bulletin_app_auth.auth_users.should == User.all.entries
+# # @new_bulletin_app_auth.auth_users_after_block_list.should_not include(@bad_stu)
+# # @new_bulletin_app_auth.save!
+# # end
+# def check_user_has_app(user_ary)
+# user_ary.each do |user|
+# user.avb_apps.should include(@bulletin_app_auth)
+# end
+# end
+# end
- end
+# end
-end
\ No newline at end of file
+# end
\ No newline at end of file
diff --git a/spec/models/app_auth_spec.rb b/spec/models/app_auth_spec.rb
index 7353f29d..4080250a 100644
--- a/spec/models/app_auth_spec.rb
+++ b/spec/models/app_auth_spec.rb
@@ -1,81 +1,81 @@
-require 'spec_helper'
-require 'ruby-debug'
+# require 'spec_helper'
+# require 'ruby-debug'
-describe AppAuth do
+# 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" => []}
- ]
+# 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
+# @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
+# 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
+# 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 ".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 ".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 ".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
+# 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
+# after(:all) do
+# @app_ary.each do |item|
+# ModuleApp.first(conditions: {title: item["name"]}).destroy
+# end
+# end
-end
\ No newline at end of file
+# end
\ No newline at end of file
diff --git a/spec/models/attribute_value_spec.rb b/spec/models/attribute_value_spec.rb
new file mode 100644
index 00000000..a9a741db
--- /dev/null
+++ b/spec/models/attribute_value_spec.rb
@@ -0,0 +1,63 @@
+#encoding: UTF-8
+require 'spec_helper'
+
+describe AttributeValue do
+ describe "#attribute_value" do
+ context "Data should be able to input and out put as aspect"
+
+ before do
+ @af = AttributeField.find '5052cf9f2b5c49a742000005'
+ @user = User.where(email:'chris@rulingcom.com').first
+ @av = AttributeValue.last
+ end #end before
+
+ [true,false].each do |locale_sat|
+ LIST[:markups].each do |markup|
+ @av = nil
+ it "[#{markup[0]}]Input: should save data at right way when local is set to #{locale_sat}" do
+ @af.markup = markup[0]
+ @av = nil
+ @input_value = assume_result = case markup[0]
+ when 'text_field','text_area'
+ (locale_sat ? {"en"=> "lalala","zh_tw"=>"拉拉拉"} : "hahaha")
+ when 'select','radio_button'
+ "1"
+ when 'date'
+ {"(1i)"=>Date.today.year.to_s,"(2i)"=>Date.today.month.to_s,"(3i)"=>Date.today.day.to_s}
+ when 'checkbox'
+ {"1"=>"true", "3"=>"true"}
+ end #end of case
+ assume_result = ["1","3"] if markup[0] == 'checkbox'
+ @af.locale = locale_sat
+ @af.save
+ @data_hash = {"attribute_field_id" => @af.id,"value" => @input_value}
+ @av = @user.attribute_values.build(@data_hash)
+ @av.save
+
+ @av.value.should == assume_result
+ # @av.destroy
+ end
+
+ it "[#{markup[0]}]Output(just for show): should output data at right way when local is set to #{locale_sat}" do
+ locale = I18n.locale
+ assume_result = case markup[0]
+ when 'text_area'
+ (locale_sat ? "拉拉拉" : "hahaha")
+ when 'text_field'
+ (locale_sat ? "拉拉拉" : "hahaha")
+ when 'select','radio_button'
+ (locale_sat ? "男性" : "男性")
+ when 'date'
+ Date.today
+ when 'checkbox'
+ (locale_sat ? "男性,不公開" : "男性,不公開")
+ end #end of case
+
+ @av.get_value_by_locale(locale).should == assume_result
+ end
+
+ end #end of LIST loop
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb
index a58799b4..0d8d2fe9 100644
--- a/spec/models/role_spec.rb
+++ b/spec/models/role_spec.rb
@@ -1,113 +1,113 @@
-require 'spec_helper'
+ # 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
+# 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
\ No newline at end of file
+# end
\ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2529da0f..cd0b93ad 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -38,6 +38,7 @@ Spork.prefork do
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
+
end
end