add new member with role interface. add more not usable.

role management new attribute is ok. delete is ok.
This commit is contained in:
Matthew K. Fu JuYuan 2012-11-04 05:56:29 +08:00
parent 664c6d2f61
commit e47465d4b7
33 changed files with 1098 additions and 578 deletions

View File

@ -287,36 +287,42 @@
padding: 0 20px 0 150px !important; padding: 0 20px 0 150px !important;
margin: 20px 0 0; margin: 20px 0 0;
} }
.user-role .user-info { .role-block .user-info {
top: 23px; top: 23px;
margin-left: -135px; margin-left: -135px;
width: 100px; width: 100px;
border-right: none; border-right: none;
box-shadow: none; box-shadow: none;
} }
.user-role .map-block h4 .gender { .role-block .map-block h4 .gender {
top: -1px; top: -1px;
bottom: auto; bottom: auto;
left: -1px; left: -1px;
right: auto; right: auto;
border-radius: 4px 0 0 0; border-radius: 4px 0 0 0;
} }
.user-role .teacher h4 .gender { .role-block .teacher h4 .gender {
border-color: #186AB6 transparent transparent #186AB6; border-color: #186AB6 transparent transparent #186AB6;
} }
.user-role .student h4 .gender { .role-block .student h4 .gender {
border-color: #F38C08 transparent transparent #F38C08; border-color: #F38C08 transparent transparent #F38C08;
} }
.user-role .staff h4 .gender { .role-block .staff h4 .gender {
border-color: #139E2F transparent transparent #139E2F; border-color: #139E2F transparent transparent #139E2F;
} }
.user-role .tab-content, .user-role .nav-pills { .role-block .tab-content, .role-block .nav-pills {
float: left; float: left;
} }
.user-role .nav-pills { .role-block .nav-pills {
margin-left: 10px; margin-bottom: 0;g
} }
.plural .input-append input, .plural .input-append select, .plural .input-append .uneditable-input { .role-block .nav-pills > li > a {
margin-top: 0;
}
/*.role-block .control-group .inline {
float:
}*/
.plural .input-append input, .plural .input-append select, .plural .input-append .uneditable-input, .unRadius input {
-webkit-border-radius: 3px; -webkit-border-radius: 3px;
-moz-border-radius: 3px; -moz-border-radius: 3px;
border-radius: 3px; border-radius: 3px;
@ -338,4 +344,8 @@
-webkit-border-radius: 0 3px 3px 0; -webkit-border-radius: 0 3px 3px 0;
-moz-border-radius: 0 3px 3px 0; -moz-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0;
}
.language-swich .tab-pane {
margin-bottom: 5px;
margin-right: 10px;
} }

View File

@ -81,37 +81,60 @@
background-color: #5EB92B; background-color: #5EB92B;
font-size: 9px; font-size: 9px;
padding: 0px 10px; padding: 0px 10px;
border-radius: 8px; border-radius: 11px;
line-height: 16px; line-height: 20px;
height: 15px; height: 19px;
color: #FFF; color: #FFF;
width: 38px; width: 40px;
border: none; border: none;
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.5), 0 0 5px rgba(13, 75, 23, 0.5) inset; box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.5), 0 0 5px rgba(13, 75, 23, 0.5) inset;
margin-top: 2px; margin-top: 1px;
} }
/* for mamber role */ /* for mamber role */
.role-block .form-horizontal {
.user-role .form-horizontal {
padding: 20px 10px 10px; padding: 20px 10px 10px;
background-color: #FFF; background-color: #FFF;
margin-bottom: 0; margin-bottom: 0;
border-radius: 0 0 4px 4px; border-radius: 0 0 4px 4px;
} }
.user-role .form-horizontal .control-label { .role-block [class*="type"] {
background-color: #F1F1F1;
padding: 20px 0 10px;
border-radius: 5px;
margin: -25px 0 40px;
/*box-shadow: 0px 1px 3px rgba(100,100,100,.4)*/
}
.role-block .form-horizontal .control-label {
width: 100px; width: 100px;
} }
.user-role .form-horizontal .controls { .role-block .form-horizontal .controls {
margin-left: 120px; margin-left: 120px;
} }
.user-role .form-horizontal .controls>.input-append { .role-block .form-horizontal .controls>.input-append {
margin-bottom: 10px; margin-bottom: 10px;
} }
.user-role .map-block { .role-block .form-horizontal legend .onoff {
margin-top: 4px;
}
.role-block .form-horizontal legend .btn-danger {
margin-right: 20px;
}
.role-block .form-horizontal legend>.clear {
margin-right: 150px;
min-width: 350px;
}
.role-block .map-block {
min-width: 440px; min-width: 440px;
} }
.user-role .map-block legend { .role-block .map-block .form-actions {
margin: 0;
padding: 10px 20px;
}
.role-block .map-block legend {
font-size: 18px; font-size: 18px;
line-height: 25px; line-height: 25px;
} }
.role-block .map-block legend .nav {
font-size: 12px;
}

View File

@ -1,10 +1,11 @@
class Admin::InfosController < ApplicationController class Admin::InfosController < ApplicationController
layout "admin" layout "new_admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :is_admin? before_filter :is_admin?
before_filter :set_attribute, :only => [:index, :show, :new, :edit] before_filter :set_attribute, :only => [:index, :show, :new, :edit]
helper Admin::AttributeValuesViewHelper
def index def index
@attributes = Info.all.entries @attributes = Info.all.entries
render :template => 'admin/attributes/index' render :template => 'admin/attributes/index'
@ -32,8 +33,8 @@ class Admin::InfosController < ApplicationController
def update def update
@attribute = Info.find(params[:id]) @attribute = Info.find(params[:id])
# binding.pry
@attribute.update_attributes(params[:info]) @attribute.update_attributes(params[:info])
@attribute.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
respond_to do |format| respond_to do |format|
format.html { redirect_to :action => :index } format.html { redirect_to :action => :index }
format.js { render 'admin/attributes/toggle_enable' } format.js { render 'admin/attributes/toggle_enable' }
@ -47,10 +48,10 @@ class Admin::InfosController < ApplicationController
end end
def add_attribute_field def add_attribute_field
@attribute = Info.find(params[:id]) rescue nil attribute = Info.find(params[:info_id]) rescue nil
if !@attribute @attribute_field_counter = attribute.attribute_fields.count
@attribute = Info.new @attribute_field = attribute.attribute_fields.build
end @attribute_field.save
end end
protected protected

View File

@ -75,7 +75,6 @@ class Admin::UsersNewInterfaceController < ApplicationController
end end
def create def create
binding.pry
puts params.to_yaml puts params.to_yaml
# attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values' # attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
# attribute_values = params[:user].delete(attribute_values_key) # attribute_values = params[:user].delete(attribute_values_key)
@ -84,6 +83,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
# @user.attribute_values.build(value) # @user.attribute_values.build(value)
# } # }
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values) # @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
binding.pry
if @user.save if @user.save
flash[:notice] = t('admin.create_success_user') flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index redirect_to :action => :index

View File

@ -0,0 +1,16 @@
module Admin::AttributeValuesViewHelper
OPT = [
["YYYY / MM / DD hh : mm","format1"],
["YYYY / MM / DD","format2"],
["YYYY / MM","format3"],
["YYYY","format4"]
]
def show_type_panel(attribute_field,type)
markup = attribute_field.markup
LIST[:markups][markup]["panel"] == type ? type : [type,'hide'].join(" ")
end
def name_to_id(str)
str.gsub(/\]/,'').gsub(/\[/,"_")
end
end

View File

@ -9,14 +9,18 @@ module AttributeFieldsHelper
include ActionView::Helpers::RenderingHelper include ActionView::Helpers::RenderingHelper
def block_helper(user,index,disable = false) def block_helper(user,index,disable = false)
@index = index unless self.disabled
@markup_options = markup_options.merge(:disabled=>disable) @index = index
@user = user @markup_options = markup_options.merge(:disabled=>disable,:func=>"input_unit")
@attribute_value = @user.get_value_from_field_id(id) @user = user
@new_attribute = @attribute_value.nil? @attribute_value = @user.get_value_from_field_id(id)
@attribute_value = @attribute_value || @user.attribute_values.build(attribute_field_id: id) @new_attribute = @attribute_value.nil?
@prefiled_value = @attribute_value.get_values @attribute_value = @attribute_value || @user.attribute_values.build( attribute_field_id: id )
return instance_eval("render_#{markup}") #rescue "" @prefiled_value = @attribute_value.value
@panel_setting = self.get_data
return instance_eval("render_#{markup}") #rescue ""
end
end end
def lang_tab(str,lang) def lang_tab(str,lang)
@ -24,6 +28,7 @@ module AttributeFieldsHelper
end end
def render_address def render_address
#NP
control_group_wrapper do |key,value| control_group_wrapper do |key,value|
result = '<div class="input-append">'.html_safe result = '<div class="input-append">'.html_safe
@ -44,36 +49,55 @@ module AttributeFieldsHelper
end end
def render_checkbox def render_checkbox
@prefiled_value ||=[] @prefiled_value ||=[]
markup_value = eval(self.markup_value) rescue {} # begin
# markup_value = eval(self.markup_value)
# rescue
# markup_value = self.markup_value
# ensure
# markup_value ||= {}
# end
control_group_wrapper do control_group_wrapper do
markup_value.collect do |key,value| a = self[:option_list].collect do |key,value|
label_tag(key,check_box_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label")) label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
end.join rescue "" end.join rescue ""
end end
end end
def render_date def render_date
control_group_wrapper{date_select(get_field_name_base+"[value]",nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")} #NP
control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
end end
def render_date_durnation #Need re-write low priority def render_date_durnation #Need re-write low priority
end end
def render_radio_button def render_radio_button
@prefiled_value ||=[] @prefiled_value ||=[]
markup_value = eval(self.markup_value) rescue {} # begin
# markup_value = eval(self.markup_value)
# rescue
# markup_value = self.markup_value
# ensure
# markup_value ||= {}
# end
control_group_wrapper do control_group_wrapper do
markup_value.collect do |key,value| self[:option_list].collect do |key,value|
label_tag(key,radio_button_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label")) label_tag(key,radio_button_tag(get_field_name_base, key , (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
end.join rescue "" end.join
end end
end end
def render_select def render_select
markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {}
control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue "" prompt = @panel_setting[:prompt][I18n.locale] rescue nil
@markup_options.merge!(:prompt => prompt) unless prompt.nil?
# markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {}
# check self[:option_list].collect{|p| [p[1][I18n.locale.to_s],p[0]]}
control_group_wrapper{select_tag( get_field_name_base,options_for_select(self.option_list.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue ""
end end
def render_text_area def render_text_area
@ -81,28 +105,35 @@ module AttributeFieldsHelper
if(add_more and value.is_a?(Hash)) if(add_more and value.is_a?(Hash))
values = value values = value
values.each_with_index.collect do |value,index| values.each_with_index.collect do |value,index|
text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options) place_holder= @panel_setting["placeholder"][key]
text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
end.join.html_safe end.join.html_safe
else else
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
key = can_muti_lang_input ? "[#{key}]" : "[value]" key = can_muti_lang_input ? "[#{key}]" : ""
text_area_tag(get_field_name_base + key, value,@markup_options) place_holder= @panel_setting["placeholder"][I18n.locale.to_s] rescue ''
text_area_tag(get_field_name_base + key, value,@markup_options.merge(:placeholder=>place_holder))
end end
end end
end end
def render_text_field def render_text_field
control_group_wrapper do |key,value| control_group_wrapper do |key,value|
if(add_more and value.is_a?(Hash)) if(add_more)
values = value values = value
values.each_with_index.collect do |value,index| result = ""
unless values.nil?
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options) result = values.each_with_index.collect do |value,index|
end.join.html_safe place_holder= @panel_setting["placeholder"][key]
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
end.join.html_safe
end
result
else else
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil
key = can_muti_lang_input ? "[#{key}]" : "[value]" key_field = can_muti_lang_input ? "[#{key}]" : ""
text_field_tag(get_field_name_base + key, value,@markup_options) place_holder= @panel_setting["placeholder"][key] rescue ''
text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder))
end end
end end
end end
@ -121,12 +152,14 @@ protected
if can_muti_lang_input if can_muti_lang_input
result << "<div class='tabbable'>" result << "<div class='tabbable'>"
result << "<div class='tab-content'>" result << "<div class='tab-content'>"
VALID_LOCALES.collect do |key| VALID_LOCALES.collect do |key|
value = @prefiled_value[key.to_s] rescue nil value = @prefiled_value[key.to_s] rescue nil
div_class = ["tab-pane" ,"fade"].join(" ") div_class = ["tab-pane" ,"fade"].join(" ")
div_class << (key == I18n.locale.to_s ? " active in" : '') div_class << (key == I18n.locale.to_s ? " active in" : '')
result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}") result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}")
end end
result << "</div>" result << "</div>"
result << "<ul class='nav nav-pills'>" result << "<ul class='nav nav-pills'>"
VALID_LOCALES.each do |key| VALID_LOCALES.each do |key|
@ -161,15 +194,13 @@ protected
def end_block def end_block
if @new_attribute if @new_attribute
hidden_field_tag(get_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}") hidden_field_tag(get_basic_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
else else
hidden_field_tag(get_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}") hidden_field_tag(get_basic_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}")
end end
end end
def get_field_name_base def get_basic_field_name_base
# "user[#{self.attribute._type.downcase.pluralize}][#{self.attribute._id.to_s}][attribute_values][#{attribute_value.id}]"
# binding.pry if @attribute_value[:key] == 'status'
if @new_attribute if @new_attribute
"user[new_attribute_values][#{@index}]" "user[new_attribute_values][#{@index}]"
else else
@ -177,12 +208,16 @@ protected
end end
end end
def get_field_name_base
get_basic_field_name_base + "[value]"
end
def label def label
label_tag(key,title,:class=>"control-label") label_tag(key,title,:class=>"control-label",:func => "field_label")
end end
def can_muti_lang_input def can_muti_lang_input
locale and LIST[:markups][markup]["muti_lang_input_supprt"] LIST[:markups][markup]["muti_lang_input_supprt"] #and locale
end end
def can_add_more def can_add_more

View File

@ -11,6 +11,7 @@ class Attribute
has_many :attribute_fields, :autosave => true, :dependent => :destroy has_many :attribute_fields, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
def is_built_in? def is_built_in?
self.built_in self.built_in
end end

View File

@ -5,26 +5,38 @@ class AttributeField
include ::AttributeFieldsHelper include ::AttributeFieldsHelper
field :key field :key
field :markup field :markup ,:default=>"text_field"
field :markup_value ,:type => Hash field :option_list ,:type => Hash,:default => {}
field :markup_options,:type => Hash field :markup_options,:type => Hash
field :locale, :type => Boolean, :default => true # field :locale, :type => Boolean, :default => true
# field :list_options, :type => Array # field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false
field :add_more,:type => Boolean, :default => false field :to_delete,:type=> Boolean,:default => false
field :typeA,:type=> Hash,:default=>{}
field :typeB,:type=> Hash,:default=>{}
field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar"}
field :typeD,:type=> Hash,:default=>{}
field :typeE,:type=> Hash,:default=>{}
#field :title, localize: true #field :title, localize: true
field :locale_title, localize: true field :title, localize: true
field :neutral_title
field :neutral_for
belongs_to :attribute belongs_to :attribute
# belongs_to :role # belongs_to :role
has_many :attribute_values,:autosave => true, :dependent => :destroy has_many :attribute_values,:autosave => true, :dependent => :destroy
before_save :check_option_list
# validates_uniqueness_of :key # validates_uniqueness_of :key
def add_more
(get_data["add_more"] == "true" ? true : false) rescue false
end
def locale
(get_data["locale"] == "true" ? true : false) rescue false
end
def self_defined_markup_options? def self_defined_markup_options?
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false (self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
@ -36,16 +48,16 @@ class AttributeField
end end
end end
def markup_value def option_list
if self_defined_markup_options? if self_defined_markup_options?
#Class need to have corresponding field and value agent #Class need to have corresponding field and value agent
# Ex: For "status" the class must have field called "statuses" for the relation and "statuses_for_select" for the select function # Ex: For "status" the class must have field called "statuses" for the relation and "statuses_for_select" for the select function
method = self.attribute.role.method(self[:key].pluralize+"_for_"+markup) method = self.attribute.role.method(self[:key].pluralize+"_for_"+markup)
return (method.call rescue {}) return (method.call rescue {})
elsif self[:markup_value].nil? || (self[:markup_value].empty?) elsif self[:option_list].nil? || (self[:option_list].empty?)
return {} return {}
else else
return self[:markup_value] return self[:option_list]
end end
end end
@ -68,36 +80,49 @@ class AttributeField
self.attribute.role self.attribute.role
end end
def title_translations def panel
if locale panel = LIST[:markups][self[:markup]]["panel"]
return locale_title_translations
else
return Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
end
end end
def title_translations=(var) def get_data
if locale self[panel]
self.locale_title_translations = var
end
end end
def title
if locale
return self.locale_title
else
return self.neutral_title
end
end
def title=(var) # def title_translations
# binding.pry # if locale
if locale # return self.locale_title_translations
self.locale_title = var # else
else # return self[:neutral_title] #Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
self.neutral_title = var # end
end # end
end
# def title_translations=(var)
# if locale
# self.locale_title_translations = var
# end
# end
# def title
# if locale
# return self.locale_title
# else
# return self.neutral_title
# end
# end
# def check_title
# if locale
# self.locale_title_translations = self[:temp_title]
# else
# self.neutral_title = self[:temp_title]
# end
# self.unset("temp_title")
# end
# def title=(var)
# self["temp_title"] = var
# end
# # Convert the string list_options into an array # # Convert the string list_options into an array
# def select_list_options=(var) # def select_list_options=(var)
@ -117,4 +142,9 @@ class AttributeField
self.disabled self.disabled
end end
protected
def check_option_list
self[:option_list] = self[panel]["option_list"]
end
end end

View File

@ -10,11 +10,56 @@ class AttributeValue
belongs_to :user belongs_to :user
before_save :check_key before_save :check_key
before_save :data_proc
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"] # NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
def data_proc
# binding.pry
# binding.pry if self.attribute_field.markup == 'radio_button'
if self.attribute_field.locale
case self.attribute_field.markup
when 'text_field','text_area'
# binding.pry
self[:temp_data].each{|key,val|
self[key] = val
} unless self[:temp_data].nil?
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys rescue {}
end #end of case
else # if not locale
case self.attribute_field.markup
when 'text_field','text_area'
self["val"] = self[:temp_data]
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys rescue {}
end #end of case
end
self.unset('temp_data')
end
def value
result=""
if self.attribute_field.locale && (self.attribute_field.markup == "text_field" || self.attribute_field.markup == "text_area")
result= Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
else
result = self["val"]
end
result
end
def value=(value)
#save everything to temp_data waiting for futher process
# binding
self[:temp_data] = value
end
def check_key def check_key
binding.pry if attribute_field.nil?
self.key = attribute_field.key self.key = attribute_field.key
end end
@ -27,45 +72,46 @@ class AttributeValue
end end
def get_value_by_locale(locale) def get_value_by_locale(locale)
case self.attribute_field.markup case self.attribute_field.markup
when "text_field" when "text_field"
self.attribute_field.locale ? self[locale] : self[:value] self.attribute_field.locale ? self.value[locale.to_s] : self.value
when "select" when "select"
markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value) markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value)
markup_values[self[:value]][locale.to_s] rescue 'NoData' markup_values[self.value][locale.to_s] rescue 'NoData'
when "text_area" when "text_area"
self.attribute_field.locale ? self[locale] : self[:value] self.attribute_field.locale ? self.value[locale.to_s] : self.value
when "date" when "date"
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i) rescue nil Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
when "addr" when "addr"
self[:value] self.value
when "radio_button" when "radio_button"
markup_values = eval(self.attribute_field.markup_value) markup_values = eval(self.attribute_field.markup_value)
markup_values[self[:value].first[0]][locale.to_s] markup_values[self.value][locale.to_s]
when "checkbox" when "checkbox"
markup_values = eval(self.attribute_field.markup_value) markup_values = eval(self.attribute_field.markup_value)
self[:value].keys.collect{|key| markup_values[key][locale.to_s] }.join(",") self.value.collect{|key| markup_values[key][locale.to_s] }.join(",")
when "date_durnation" when "date_durnation"
self[:value] self.value
else else
self.attribute_field.locale ? self[locale] : self[:value] self.attribute_field.locale ? self.value[locale.to_s] : self.value
end end
end end
def get_values # def get_values
unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup ) # unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup )
if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"] # if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}] # return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}]
else # else
return get_value_by_locale("") # return get_value_by_locale("")
end # end
else # else
if self.attribute_field.markup == "select" # if self.attribute_field.markup == "select"
self[:value] # self[:value]
else # else
self[:value].keys rescue self[:value] # self[:value].keys rescue self[:value]
end # end
end # end
end # end
end end

View File

@ -38,7 +38,8 @@ class User
before_save :save_roles before_save :save_roles
scope :remote_account, where(:nccu_id.ne => nil) scope :remote_account, where(:nccu_id.ne => nil)
validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique") # validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
# def new_attribute_values=(vars) # def new_attribute_values=(vars)
# binding.pry # binding.pry
# end # end

View File

@ -1,14 +1,139 @@
<% content_for :secondary do %> <%= form_for @attribute,:url => admin_info_path(@attribute) ,:class=> "form-horizontal" do |f| %>
<%= render 'admin/users/side_bar' %> <div class="site-map role-block">
<div class="map-block back">
<h4><span><%= t("admin.info")%></span></h4>
<div class="form-horizontal">
<div class="clear">
<div class="control-group pull-left">
<label class="control-label" for="key"><%= t("admin.key") %></label>
<div class="controls">
<% if @attribute.new_record? %>
<%= f.text_field :key,:placeholder=>"Key" %>
<% else %>
<div><%= @attribute.key%></div>
<% end %>
</div>
</div>
<%= render :partial=>"placeholder_block",:locals=>{:value=>@attribute.title_translations,:class_ext=>"pull-left",:label_ext=>t("admin.infos.item_name"),:field_name=>"info[title_translations]"}%>
</div>
</div>
</div>
<div class="map-block back attributes">
<h4><span><%= t("admin.attributes")%></span></h4>
<%= render :partial=>"attribute_field",:collection=>@attribute.attribute_fields%>
</div>
</div>
<div class="form-actions form-fixed pagination-right">
<%= link_to content_tag(:i,t("admin.infos.add_attribute_field"),:class=>"icon-plus icon-white"),admin_info_add_attribute_field_path(@attribute),:class=>"btn btn-primary",:remote => true%>
<%= f.submit t("admin.infos.save"),:class=>"btn btn-primary"%>
</div>
<% end %>
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "member" %>
<%= stylesheet_link_tag "site-map" %>
<% end %> <% end %>
<div id="profile"> <% content_for :page_specific_javascript do -%>
<%= form_for @attribute, :url => eval("admin_#{@attribute_type}_path(@attribute)") do |f| %> <script>
<%= f.error_messages %> var CloneTarget ;
<%= render :partial => "admin/#{@attribute_type}s/form", :locals => { :f => f, :is_new => false } %>
<div class='button_bar'> var NewNode;
<%= link_back %>
<%= link_to t('update'), "#", :onclick=>"$('#edit_#{@attribute_type}_#{@attribute.id}').submit()" %> $(document).ready(function(){
</div> // function mas(){
<% end %> // $('.site-map').masonry({
</div> // itemSelector: '.map-block',
// columnWidth: 450,
// isAnimated: true
// });
// }
function checkSwitch() {
$(".groups").addClass('disabled').has('.groups > .form-horizontal > div:not(.hide)').removeClass('disabled');
}
function checkMultipleInput() {
$(".multipleInput").each(function() {
$(this).find('.controls').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural")
});
}
function removeInput(){
$(".removeInput").live('click',function (){
$(this).parents(".controls").remove();
checkMultipleInput();
return false;
});
}
checkSwitch();
checkMultipleInput();
removeInput();
$(".remove_attribute").live('click',function(){
$(this).siblings(".attribute_field_to_delete").val("true");
$(this).parents(".form-horizontal").fadeOut("slow", function () { $(this).hide(); });
});
$(".help-block a").live('click',function (){
CloneTarget = $(this).parents(".controls").prev(".multipleInput").find('.controls:last');
NewNode = CloneTarget.clone();
var index;
NewNode.find("input").each(function(k,v){
index = CloneTarget.parents("div.control-group").find(".list_count").val()
field_name = CloneTarget.parents("div.control-group").find(".field_name").val()
ori_str = $(v).attr("name").replace(field_name,"");
lang = ori_str.match(/\[\D*\]/);
new_field_name = (field_name+"[" + (parseInt(index)+1) + "]" + lang);
$(v).attr("name",new_field_name);
})
$(this).parents("div.control-group").find(".list_count").val(parseInt(index)+1)
$(this).parents(".controls").prev(".multipleInput").append(NewNode);
$(this).parents(".controls").prev(".multipleInput").find('.controls:last input').val("");
removeInput();
checkMultipleInput();
return false;
})
$(".status select").each(function (i) {
$(this).change(function () {
$(".status option:selected").eq(i).each(function () {
if($(this).attr("value")=="alumna") {
$(this).parents(".status").nextAll(".graduated").removeClass("hide");
$(this).parents(".status").nextAll(".graduated").find("select").removeAttr("disabled");
}else{
$(this).parents(".status").nextAll(".graduated").addClass("hide");
$(this).parents(".status").nextAll(".graduated").find("select").attr({disabled:''});
}
});
})
})
$('.onoff').live('click',function () {
if($(this).parents("h4").length==1) {
$(this).parents(".map-block").toggleClass("disabled");
$(this).parents(".map-block").find(".form-horizontal").toggleClass("hide");
if($(this).parents(".map-block").hasClass("disabled")){
$(this).text("OFF");
}else{
$(this).text("ON");
}
}
if($(this).parents("legend").length==1) {
$(this).toggleClass("disabled");
$(this).parents("legend").next("div").toggleClass("hide");
if($(this).parents("legend").next("div").hasClass("hide")){
$(this).text("OFF");
$(this).siblings(".attribute_field_disabled").val("true");
}else{
$(this).text("ON");
$(this).siblings(".attribute_field_disabled").val("false");
}
checkSwitch();
}
return false;
});
$(".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");
})
});
</script>
<% end -%>

View File

@ -1,3 +1,100 @@
<%= f.fields_for :attribute_fields, attribute_field do |f| %> <div class="form-horizontal">
<%= render :partial => 'admin/attributes/attribute_field', :object => attribute_field, :locals => {:f => f} %> <legend>
<% end %> <button class="onoff pull-right <%= attribute_field.disabled ? 'disabled' : ''%>">ON</button>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","disabled",:value=>attribute_field.disabled,:class=>"attribute_field_disabled"%>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","to_delete",:value=>false,:class=>"attribute_field_to_delete"%>
<a class="btn btn-small pull-right btn-danger remove_attribute" href="#"><i class="icon-trash icon-large"></i> <%= t("delete")%></a>
<div class="clear">
<div class="control-group pull-left">
<label class="control-label" for="key"><%= t("admin.key") %></label>
<div class="multipleInput">
<div class="controls">
<%= text_field "info[attribute_fields][#{attribute_field_counter}]","key",:value=>attribute_field.key%>
</div>
</div>
</div>
<%= render :partial=>"placeholder_block",:locals=>{:values=>attribute_field.title_translations,:class_ext=>"pull-left",:label_ext=>t("admin.infos.name"),:field_name=>"info[attribute_fields][#{attribute_field_counter}][title_translations]"}%>
<div class="control-group pull-left">
<label class="control-label" for=""><%= t("admin.infos.type")%></label>
<div class="controls">
<%#= select_tag "info[attribute_fields][#{attribute_field_counter}][markup]" do %>
<select class="dataType" name=<%= "info[attribute_fields][#{attribute_field_counter}][markup]"%>>
<%LIST[:markups].each do |key,val|%>
<option value="<%= key %>" <%= attribute_field.markup == key ? 'selected="selected"' : '' %> ref="<%=val["panel"]%>"><%=t("lists.markups."+key)%></option >
<% end %>
</select>
</div>
</div>
</div>
</legend>
<div class="<%= attribute_field.disabled ? 'hide' : ''%>">
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeA") do%>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.options")%></label>
<div class="controls">
<label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][multilingual]","true",attribute_field["typeA"]["multilingual"]) %>
<%= t("admin.infos.multilingual")%>
</label>
<label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][add_more]","true",attribute_field["typeA"]["add_more"]) %>
<%= t("admin.infos.add_more")%>
</label>
</div>
</div>
<%= render :partial=> "placeholder_block",:locals=>{:values=>attribute_field["typeA"]["placeholder"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeA][placeholder]"}%>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeB") do %>
<%= render :partial=> "placeholder_block",:locals=>{:label_ext=>t("admin.infos.initial"),:values=>attribute_field["typeB"]["initial"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeB][initial]"}%>
<%= render :partial=>"list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][typeB][option_list]"} %>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeC") do %>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.date.format")%></label>
<div class="controls">
<%= select "info[attribute_fields][#{attribute_field_counter}][typeC]","format",Admin::AttributeValuesViewHelper::OPT,:class=>"dataType",:selected=>attribute_field["typeC"]["format"] %>
</div>
</div>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.date.range")%></label>
<div class="controls">
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "false",:checked => (attribute_field["typeC"]["is_range"]== "false" ? true : false)) %><%= t("admin.infos.not_range")%>
</label>
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "true",:checked => (attribute_field["typeC"]["is_range"]== "true" ? true : false)) %><%= t("admin.infos.is_range")%>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.date.claendar")%></label>
<div class="controls">
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "claendar", "west_claendar",:checked =>(attribute_field["typeC"]["claendar"]== "west_claendar" ? true : false)) %><%= t("admin.infos.date.west_claendar")%>
</label>
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "claendar", "tw_claendar",:checked =>(attribute_field["typeC"]["claendar"]== "tw_claendar" ? true : false)) %><%= t("admin.infos.date.tw_claendar")%>
</label>
</div>
</div>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeD") do%>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.options")%></label>
<div class="controls">
<label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeD][multilingual]","true",attribute_field["typeD"]["multilingual"]) %>
<%= t("admin.infos.multilingual")%>
</label>
</div>
</div>
<%= render :partial=> "placeholder_block",:locals=>{:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeD][placeholder]",:values=>attribute_field["typeD"]["placeholder"]} %>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeE") do%>
<%= render :partial=>"list_block",:locals=>{:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeE][option_list]",:values=>attribute_field["option_list"]}%>
<% end %>
</div>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","id",:value=>attribute_field.id%>
</div>

View File

@ -0,0 +1,45 @@
<% temp_field_name = field_name.gsub /\[\D*\]$/,'[temp]'%>
<div class="control-group">
<%= hidden_field_tag "#{temp_field_name}[count]",((values.keys.collect{|t| t.to_i}.max rescue nil) || 0 ),:class=>"list_count"%>
<%= hidden_field_tag "#{temp_field_name}[name]",field_name,:class=>"field_name"%>
<label class="control-label" ><%= t("admin.infos.list")%></label>
<div class="multipleInput">
<%if values.blank? %>
<div class="controls">
<% @site_valid_locales.each do |locale| %>
<% last = (locale == @site_valid_locales.last ? true : false) %>
<% p_value = value[locale.to_s] rescue nil%>
<%= content_tag :div,:class=>"input-append #{"unRadius" if last }" do%>
<%= text_field("#{field_name}[0]", locale,:placeholder=>t("langs.#{locale}")) %>
<% if last %>
<a href="#" class="btn removeInput" type="button"><i class="icon-trash"></i></a>
<% end %>
<% end %>
<% end %>
</div>
<%else%>
<%values.each do |index,value|%>
<div class="controls">
<% @site_valid_locales.each do |locale| %>
<% last = (locale == @site_valid_locales.last ? true : false) %>
<% p_value = value[locale.to_s] rescue nil%>
<%= content_tag :div,:class=>"input-append #{"unRadius" if last }" do%>
<%= text_field("#{field_name}[#{index}]", locale,:value=>p_value,:placeholder=>t("langs.#{locale}")) %>
<% if last %>
<a href="#" class="btn removeInput" type="button"><i class="icon-trash"></i></a>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
</div>
<div class="controls">
<span class="help-block">
<a href="#"><i class="icon-plus-sign"></i><%= t("admin.infos.add") %></a>
</span>
</div>
</div>

View File

@ -0,0 +1,25 @@
<% values ||=[]%>
<%= content_tag :div,:class=>"control-group language-swich #{class_ext rescue "" }" do%>
<label class="control-label" for=""><%= (defined? label_ext) ? label_ext : t("admin.infos.placeholder") %></label>
<div class="controls">
<div class="tabbable">
<div class="tab-content">
<% @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 %>
</div>
<ul class="nav nav-pills ">
<% @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 %>
</ul>
</div>
</div>
<% end %>

View File

@ -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");
})

View File

@ -14,7 +14,7 @@
<% end -%> <% 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| %> <%= form_for @user, :url => admin_users_new_interface_path(@user), :html => { :multipart => true } do |f| %>
<%= f.error_messages %> <%= f.error_messages %>

View File

@ -1,8 +0,0 @@
<table>
address
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
checkbox
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
date
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
date durnation
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
radio_button
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
select
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
text_area
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -1,8 +0,0 @@
<table>
text_field
<tr>
<td> markup_value</td>
<td> markup_options</td>
</tr>
<tr>other's options</tr>
</table>

View File

@ -9,21 +9,27 @@ markups:
text_field: text_field:
muti_lang_input_supprt: true muti_lang_input_supprt: true
ext_support: true ext_support: true
panel: typeA
select: select:
muti_lang_input_supprt: false muti_lang_input_supprt: false
ext_support: false ext_support: false
panel: typeB
date: date:
muti_lang_input_supprt: false muti_lang_input_supprt: false
ext_support: false ext_support: false
panel: typeC
text_area: text_area:
muti_lang_input_supprt: true muti_lang_input_supprt: true
ext_support: false ext_support: false
panel: typeD
radio_button: radio_button:
muti_lang_input_supprt: false muti_lang_input_supprt: false
ext_support: false ext_support: false
panel: typeE
checkbox: checkbox:
muti_lang_input_supprt: false muti_lang_input_supprt: false
ext_support: false ext_support: false
panel: typeE
# date_durnation: # date_durnation:
# muti_lang_input_supprt: false # muti_lang_input_supprt: false
# ext_support: false # ext_support: false

View File

@ -30,6 +30,14 @@ en:
langs: langs:
zh_tw: Traditional Chinese zh_tw: Traditional Chinese
en: English en: English
lists:
markups:
text_field: Text Field
select: Select
date: Date
text_area: Text Area
radio_button: Radio button
checkbox: Checkbox
login: Login login: Login
logout: Logout logout: Logout
no_: "No" no_: "No"

View File

@ -27,6 +27,14 @@ zh_tw:
langs: langs:
zh_tw: 中文 zh_tw: 中文
en: 英文 en: 英文
lists:
markups:
text_field: 文字輸入框
select: 下拉選單
date: 日期
text_area: 文字輸入方塊
radio_button: 單選
checkbox: 多選
login: 登入 login: 登入
logout: 登出 logout: 登出
nccu: 政大 nccu: 政大
@ -83,8 +91,30 @@ zh_tw:
errors: errors:
at_least_one: 必須至少有一個值 at_least_one: 必須至少有一個值
admin: 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: access:
denied: denied:
app: app:

View File

@ -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

View File

@ -1,218 +1,218 @@
require 'spec_helper' # require 'spec_helper'
require 'ruby-debug' # require 'ruby-debug'
describe AppAuth do # describe AppAuth do
before do # before do
User.all.destroy # User.all.destroy
Role.all.destroy # Role.all.destroy
SubRole.all.destroy # SubRole.all.destroy
AppAuth.all.destroy # AppAuth.all.destroy
ModuleApp.all.destroy # ModuleApp.all.destroy
#Create some fixtures of Main Role # #Create some fixtures of Main Role
main_role_key = ["Stud","Teacher","Staff"] # main_role_key = ["Stud","Teacher","Staff"]
@new_main_role_list = main_role_key.each do |role| # @new_main_role_list = main_role_key.each do |role|
new_role = Role.new :key => role # new_role = Role.new :key => role
new_role.save # new_role.save
end # end
#Create Some SubRoles # #Create Some SubRoles
sub_role_key = ["graduated_school","undergraduated_school","TA","Senior"] # sub_role_key = ["graduated_school","undergraduated_school","TA","Senior"]
@new_main_role_list = sub_role_key.each do |role| # @new_main_role_list = sub_role_key.each do |role|
new_role = SubRole.new :key => role # new_role = SubRole.new :key => role
new_role.save # new_role.save
end # end
#Create some users of User # #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 = ["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| # user_emails.each do |user_email|
email=user_email+"@rulingcom.com" # email=user_email+"@rulingcom.com"
new_user = User.new :email=> email # new_user = User.new :email=> email
new_user.save # new_user.save
end # end
#MRK = Member Role Key SRK=Sub Role Key # #MRK = Member Role Key SRK=Sub Role Key
@stud_MRK = Role.first(conditions:{key:"Stud"}) # @stud_MRK = Role.first(conditions:{key:"Stud"})
@teacher_MRK = Role.first(conditions:{key:"Teacher"}) # @teacher_MRK = Role.first(conditions:{key:"Teacher"})
@staff_MRK = Role.first(conditions:{key:"Staff"}) # @staff_MRK = Role.first(conditions:{key:"Staff"})
@graduated_SRK = SubRole.first(conditions:{key:"graduated_school"}) # @graduated_SRK = SubRole.first(conditions:{key:"graduated_school"})
@under_graduated_SRK = SubRole.first(conditions:{key:"undergraduated_school"}) # @under_graduated_SRK = SubRole.first(conditions:{key:"undergraduated_school"})
@ta_SRK = SubRole.first(conditions:{key:"TA"}) # @ta_SRK = SubRole.first(conditions:{key:"TA"})
@senior_SRK = SubRole.first(conditions:{key:"Senior"}) # @senior_SRK = SubRole.first(conditions:{key:"Senior"})
@stud_MRK.sub_roles += [@graduated,@under_graduated,@ta] # @stud_MRK.sub_roles += [@graduated,@under_graduated,@ta]
@stud_MRK.save! # @stud_MRK.save!
@teacher_MRK.sub_roles = [@senior] # @teacher_MRK.sub_roles = [@senior]
@teacher_MRK.save! # @teacher_MRK.save!
@good_ug_stu_1 = User.first(conditions:{email:"a_good_ug_stud_1@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"}) # @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"}) # @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"}) # @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"}) # @bad_g_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
@teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"}) # @teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"})
@staff = User.first(conditions:{email:"a_staff@rulingcom.com"}) # @staff = User.first(conditions:{email:"a_staff@rulingcom.com"})
#setting Roles for users # #setting Roles for users
@good_g_stu.role = @stud_MRK # @good_g_stu.role = @stud_MRK
@bad_g_stu.role = @stud_MRK # @bad_g_stu.role = @stud_MRK
@good_ug_stu_1.role = @stud_MRK # @good_ug_stu_1.role = @stud_MRK
@good_ug_stu_2.role = @stud_MRK # @good_ug_stu_2.role = @stud_MRK
@bad_ug_stu.role = @stud_MRK # @bad_ug_stu.role = @stud_MRK
@good_g_stu.sub_roles = [@graduated_SRK,@ta_SRK] # @good_g_stu.sub_roles = [@graduated_SRK,@ta_SRK]
@bad_g_stu.sub_roles << @graduated_SRK # @bad_g_stu.sub_roles << @graduated_SRK
@good_ug_stu_1.sub_roles << @under_graduated_SRK # @good_ug_stu_1.sub_roles << @under_graduated_SRK
@good_ug_stu_2.sub_roles << @under_graduated_SRK # @good_ug_stu_2.sub_roles << @under_graduated_SRK
@bad_ug_stu.sub_roles << @under_graduated_SRK # @bad_ug_stu.sub_roles << @under_graduated_SRK
@teacher.role = @teacher_MRK # @teacher.role = @teacher_MRK
@staff.role = @staff_MRK # @staff.role = @staff_MRK
@good_g_stu.save! # @good_g_stu.save!
@bad_g_stu.save! # @bad_g_stu.save!
@good_ug_stu_1.save! # @good_ug_stu_1.save!
@good_ug_stu_2.save! # @good_ug_stu_2.save!
@bad_ug_stu.save! # @bad_ug_stu.save!
@teacher.save! # @teacher.save!
@staff.save! # @staff.save!
end # end
describe "Starting a ClassBulletin Auth for teacher , staff and ta" do # describe "Starting a ClassBulletin Auth for teacher , staff and ta" do
before do # before do
@bulletin_app_auth = AppAuth.new() # @bulletin_app_auth = AppAuth.new()
#all teacher and staff has access right # #all teacher and staff has access right
@bulletin_app_auth.roles = [@teacher_MRK,@staff_MRK] # @bulletin_app_auth.roles = [@teacher_MRK,@staff_MRK]
#all person with TA sub_role has access right # #all person with TA sub_role has access right
@bulletin_app_auth.sub_roles << @ta_SRK # @bulletin_app_auth.sub_roles << @ta_SRK
#a_bad_ug_stud add to block to bulletin_app_auth # #a_bad_ug_stud add to block to bulletin_app_auth
#@bulletin_app_auth.blocked_users << @bad_ug_stu # #@bulletin_app_auth.blocked_users << @bad_ug_stu
#all teacher has access right # #all teacher has access right
# @bulletin_app_auth.roles << @teacher_MRK # # @bulletin_app_auth.roles << @teacher_MRK
# @bulletin_app_auth.privilege_users << @staff # # @bulletin_app_auth.privilege_users << @staff
@bulletin_app_auth.save! # @bulletin_app_auth.save!
end # end
context "Should just initialize all obj that is needed" do # context "Should just initialize all obj that is needed" do
it "Testing @bulletin_app_auth init result" do # it "Testing @bulletin_app_auth init result" do
@bulletin_app_auth.roles.should have(2).item #teacher staff # @bulletin_app_auth.roles.should have(2).item #teacher staff
@bulletin_app_auth.sub_roles.should have(1).item #ta # @bulletin_app_auth.sub_roles.should have(1).item #ta
end # end
it "@bulletin_app_auth should have Roles: Staff , Teacher " do # it "@bulletin_app_auth should have Roles: Staff , Teacher " do
key_ary = @bulletin_app_auth.roles.collect do |role| # key_ary = @bulletin_app_auth.roles.collect do |role|
role.key # role.key
end # end
key_ary.sort.should == ["Staff","Teacher"].sort # key_ary.sort.should == ["Staff","Teacher"].sort
end # end
it "bulletin_app_auth should have 3 auth users" do # it "bulletin_app_auth should have 3 auth users" do
user_ary = [@teacher,@staff,@good_g_stu] # user_ary = [@teacher,@staff,@good_g_stu]
@bulletin_app_auth.auth_users.sort.should == user_ary.sort # @bulletin_app_auth.auth_users.sort.should == user_ary.sort
check_user_has_app user_ary # check_user_has_app user_ary
end # end
it "Adding a undergraduate stud into app_auth by privilege list" do # it "Adding a undergraduate stud into app_auth by privilege list" do
user_ary = [@teacher,@staff,@good_g_stu,@good_ug_stu_1] # 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.add_user_to_privilege_list @good_ug_stu_1
@bulletin_app_auth.auth_users.sort.should == user_ary.sort # @bulletin_app_auth.auth_users.sort.should == user_ary.sort
check_user_has_app user_ary # check_user_has_app user_ary
end # end
it "Adding all graudated-stud into app_auth" do # it "Adding all graudated-stud into app_auth" do
user_ary = [@teacher,@staff,@good_g_stu,@bad_g_stu] # user_ary = [@teacher,@staff,@good_g_stu,@bad_g_stu]
@bulletin_app_auth.add_sub_role @graduated_SRK # @bulletin_app_auth.add_sub_role @graduated_SRK
@bulletin_app_auth.auth_users.sort.should == user_ary.sort # @bulletin_app_auth.auth_users.sort.should == user_ary.sort
check_user_has_app user_ary # check_user_has_app user_ary
end # end
it "Blocking bad-graduate student" do # it "Blocking bad-graduate student" do
user_ary =[@teacher,@staff,@good_g_stu] # user_ary =[@teacher,@staff,@good_g_stu]
@bulletin_app_auth.add_sub_role @graduated_SRK # @bulletin_app_auth.add_sub_role @graduated_SRK
@bulletin_app_auth.add_user_to_black_list @bad_g_stu # @bulletin_app_auth.add_user_to_black_list @bad_g_stu
@bulletin_app_auth.auth_users_after_block_list.sort.should == user_ary.sort # @bulletin_app_auth.auth_users_after_block_list.sort.should == user_ary.sort
check_user_has_app user_ary # check_user_has_app user_ary
end # end
it "Removing all graudated-stud from app_auth" do # it "Removing all graudated-stud from app_auth" do
user_ary =[@teacher,@staff,@good_g_stu] # user_ary =[@teacher,@staff,@good_g_stu]
@bulletin_app_auth.add_sub_role @graduated_SRK # @bulletin_app_auth.add_sub_role @graduated_SRK
@bulletin_app_auth.remove_sub_role @graduated_SRK # @bulletin_app_auth.remove_sub_role @graduated_SRK
@bulletin_app_auth.auth_users.sort.should == user_ary.sort # @bulletin_app_auth.auth_users.sort.should == user_ary.sort
check_user_has_app user_ary # check_user_has_app user_ary
end # end
# it "@bulletin_app_auth should have one Privialage user which is belongs to Staff" do # # 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_ary = @bulletin_app_auth.privilege_users.collect do |p_user|
# p_user.roles.key # # p_user.roles.key
# end # # end
# p_user_ary.should include("Staff") # # p_user_ary.should include("Staff")
# end # # end
# it "@bulletin_app_auth should have one student listed at blocklist" do # # it "@bulletin_app_auth should have one student listed at blocklist" do
# @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"}) # # @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 have(1).item
# @bulletin_app_auth.blocked_users.should include(@bad_stu) # # @bulletin_app_auth.blocked_users.should include(@bad_stu)
# end # # end
# it "[Development #1]-1.Authorizing roles: roles + blocklist" do # # it "[Development #1]-1.Authorizing roles: roles + blocklist" do
# @good_stu = User.first(conditions:{email:"a_good_g_stud@rulingcom.com"}) # # @good_stu = User.first(conditions:{email:"a_good_g_stud@rulingcom.com"})
# @teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"}) # # @teacher = User.first(conditions:{email:"a_teacher@rulingcom.com"})
# @staff = User.first(conditions:{email:"a_staff@rulingcom.com"}) # # @staff = User.first(conditions:{email:"a_staff@rulingcom.com"})
# ary = [@good_stu,@teacher,@staff] # # ary = [@good_stu,@teacher,@staff]
# @bulletin_app_auth.auth_users_after_block_list.should == ary # # @bulletin_app_auth.auth_users_after_block_list.should == ary
# end # # end
# # #
# it "[Development #1]-2.Authorizing single users: list of users [new_user1~2]" do # # 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 = ["new_user1","new_user2","new_user3","new_user4"]
# user_emails.each do |user_email| # # user_emails.each do |user_email|
# email=user_email+"@rulingcom.com" # # email=user_email+"@rulingcom.com"
# new_user = User.new :email=> email # # new_user = User.new :email=> email
# new_user.save # # new_user.save
# end # # end
# user1= User.first(conditions:{email:"new_user1@rulingcom.com"}) # # user1= User.first(conditions:{email:"new_user1@rulingcom.com"})
# user2= User.first(conditions:{email:"new_user2@rulingcom.com"}) # # user2= User.first(conditions:{email:"new_user2@rulingcom.com"})
# user3= User.first(conditions:{email:"new_user3@rulingcom.com"}) # # user3= User.first(conditions:{email:"new_user3@rulingcom.com"})
# user4= User.first(conditions:{email:"new_user4@rulingcom.com"}) # # user4= User.first(conditions:{email:"new_user4@rulingcom.com"})
# # #
# @bulletin_app_auth.privilege_users << user1 # # @bulletin_app_auth.privilege_users << user1
# @bulletin_app_auth.privilege_users << user2 # # @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 include(user1,user2)
# @bulletin_app_auth.auth_users_after_block_list.should_not include(user3,user4) # # @bulletin_app_auth.auth_users_after_block_list.should_not include(user3,user4)
# # #
# end # # end
# # #
# it "[Development #1]-3.Authorizing roles and single users: roles + blocklist + list of users" do # # it "[Development #1]-3.Authorizing roles and single users: roles + blocklist + list of users" do
# @bulletin_app_auth.auth_users.should have(7).item # # @bulletin_app_auth.auth_users.should have(7).item
# end # # end
# # #
# it "[Development #1]-4.Authorizing all: blocklist" do # # it "[Development #1]-4.Authorizing all: blocklist" do
# @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"}) # # @bad_stu = User.first(conditions:{email:"a_bad_g_stud@rulingcom.com"})
# @new_bulletin_app_auth = (AppAuth.new :all => true) # # @new_bulletin_app_auth = (AppAuth.new :all => true)
# @new_bulletin_app_auth.blocked_users << @bad_stu # # @new_bulletin_app_auth.blocked_users << @bad_stu
# # #
# @new_bulletin_app_auth.auth_users.should == User.all.entries # # @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.auth_users_after_block_list.should_not include(@bad_stu)
# @new_bulletin_app_auth.save! # # @new_bulletin_app_auth.save!
# end # # end
def check_user_has_app(user_ary) # def check_user_has_app(user_ary)
user_ary.each do |user| # user_ary.each do |user|
user.avb_apps.should include(@bulletin_app_auth) # user.avb_apps.should include(@bulletin_app_auth)
end # end
end # end
end # end
end # end
end # end

View File

@ -1,81 +1,81 @@
require 'spec_helper' # require 'spec_helper'
require 'ruby-debug' # require 'ruby-debug'
describe AppAuth do # describe AppAuth do
before(:all) do # before(:all) do
@app_ary = [ # @app_ary = [
{"name" => "G_app_1" , "all" => false,"blockusers" => ["a_bad_stud@rulingcom.com"]}, # {"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_2" , "all" => true,"blockusers" => ["a_bad_stud@rulingcom.com"]},
{"name" => "G_app_3_for_bad" , "all" => true,"blockusers" => []} # {"name" => "G_app_3_for_bad" , "all" => true,"blockusers" => []}
] # ]
@app_ary.each do |t| # @app_ary.each do |t|
a = ModuleApp.new :title => t["name"] # a = ModuleApp.new :title => t["name"]
blocked_users = t["blockusers"].collect do |b_user| # blocked_users = t["blockusers"].collect do |b_user|
User.first(conditions:{email:b_user}) # User.first(conditions:{email:b_user})
end # end
a.create_app_auth :all=> t["all"],:blocked_users => blocked_users # a.create_app_auth :all=> t["all"],:blocked_users => blocked_users
a.save! # a.save!
end # end
@good_stud_become_bad = User.first(conditions:{email:"a_good_stud@rulingcom.com"}) # @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"}) # @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_1 = ModuleApp.first(conditions:{title:"G_app_1"})
@g_app_2 = ModuleApp.first(conditions:{title:"G_app_2"}) # @g_app_2 = ModuleApp.first(conditions:{title:"G_app_2"})
@g_app_3 = ModuleApp.first(conditions:{title:"G_app_3_for_bad"}) # @g_app_3 = ModuleApp.first(conditions:{title:"G_app_3_for_bad"})
end # end
describe "[Init status check]" do # describe "[Init status check]" do
it "bad_stud_become_good status " 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_1.app_auth
@bad_stud_become_good.avb_apps.should_not include @g_app_2.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 # @bad_stud_become_good.avb_apps.should include @g_app_3.app_auth
end # end
it "good_stud_become_bad status " do # 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_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_2.app_auth
@good_stud_become_bad.avb_apps.should include @g_app_3.app_auth # @good_stud_become_bad.avb_apps.should include @g_app_3.app_auth
end # end
end # end
describe ".add_user_to_black_list sutd" do # describe ".add_user_to_black_list sutd" do
it "When good stud is blocked with app1 and app2" 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_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 # @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_1.app_auth
@good_stud_become_bad.avb_apps.should_not include @g_app_2.app_auth # @good_stud_become_bad.avb_apps.should_not include @g_app_2.app_auth
end # end
end # end
describe ".remove_user_from_black_list sutd" do # describe ".remove_user_from_black_list sutd" do
it "When bad stud is authed with app1 and app2" 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_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 # @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_1.app_auth
@bad_stud_become_good.avb_apps.should include @g_app_2.app_auth # @bad_stud_become_good.avb_apps.should include @g_app_2.app_auth
end # end
end # end
describe ".add_user_to_privilege_list sutd" do # describe ".add_user_to_privilege_list sutd" do
it "When bad stud is auth for one more app" 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 # @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 # @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 # @bad_stud_become_good.avb_apps.should include @g_app_1.app_auth #check
end # end
end # end
describe ".remove_user_from_privilege_list sutd" do # describe ".remove_user_from_privilege_list sutd" do
it "admin mistake. remove user from privilege list" do # it "admin mistake. remove user from privilege list" do
@g_app_1.app_auth.remove_user_from_privilege_list @bad_stud_become_good # @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 # @bad_stud_become_good.avb_apps.should_not include @g_app_1.app_auth
end # end
end # end
after(:all) do # after(:all) do
@app_ary.each do |item| # @app_ary.each do |item|
ModuleApp.first(conditions: {title: item["name"]}).destroy # ModuleApp.first(conditions: {title: item["name"]}).destroy
end # end
end # end
end # end

View File

@ -5,13 +5,12 @@ describe AttributeValue do
describe "#attribute_value" do describe "#attribute_value" do
context "Data should be able to input and out put as aspect" context "Data should be able to input and out put as aspect"
before(:each) do before do
@af = AttributeField.find '5052cf9f2b5c49a742000005' @af = AttributeField.find '5052cf9f2b5c49a742000005'
@user = User.where(email:'chris@rulingcom.com').first @user = User.where(email:'chris@rulingcom.com').first
@av = AttributeValue.last @av = AttributeValue.last
end #end before end #end before
[true,false].each do |locale_sat| [true,false].each do |locale_sat|
LIST[:markups].each do |markup| LIST[:markups].each do |markup|
@av = nil @av = nil
@ -34,6 +33,7 @@ describe AttributeValue do
@data_hash = {"attribute_field_id" => @af.id,"value" => @input_value} @data_hash = {"attribute_field_id" => @af.id,"value" => @input_value}
@av = @user.attribute_values.build(@data_hash) @av = @user.attribute_values.build(@data_hash)
@av.save @av.save
@av.value.should == assume_result @av.value.should == assume_result
# @av.destroy # @av.destroy
end end

View File

@ -1,113 +1,113 @@
require 'spec_helper' # require 'spec_helper'
describe Role do # describe Role do
before do # before do
@role = Role.create(:key => 'teacher', # @role = Role.create(:key => 'teacher',
:i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'}, # :i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'},
:sub_roles => [{:key => 'undergrad', # :sub_roles => [{:key => 'undergrad',
:i18n_variable => {:key => 'yeah', :en => 'Yeah', :zh_tw => 'Yeah', :document_class => 'Role'}, # :i18n_variable => {:key => 'yeah', :en => 'Yeah', :zh_tw => 'Yeah', :document_class => 'Role'},
:attribute_fields => [{:key => 'department'}, # :attribute_fields => [{:key => 'department'},
{:key => 'room'}]}, # {:key => 'room'}]},
{:key => 'master', # {:key => 'master',
:attribute_fields => [{:key => 'department'}]}]) # :attribute_fields => [{:key => 'department'}]}])
end # end
describe 'New role' do # describe 'New role' do
describe '#Role' do # describe '#Role' do
it 'should have :built_in false' do # it 'should have :built_in false' do
@role.built_in.should be false # @role.built_in.should be false
end # end
it 'should have :disabled false' do # it 'should have :disabled false' do
@role.disabled.should be false # @role.disabled.should be false
end # end
it 'should have a i18n_variable' do # it 'should have a i18n_variable' do
@role.i18n_variable.should be_an_instance_of I18nVariable # @role.i18n_variable.should be_an_instance_of I18nVariable
end # end
it 'should create sub_roles' do # it 'should create sub_roles' do
@role.should have(2).sub_roles # @role.should have(2).sub_roles
end # end
it 'should create attribute_fields' do # it 'should create attribute_fields' do
@role.sub_roles[1].should have(1).attribute_fields # @role.sub_roles[1].should have(1).attribute_fields
end # end
end # end
describe '#SubRole' do # describe '#SubRole' do
it 'should have :built_in false' do # it 'should have :built_in false' do
@role.sub_roles[0].built_in.should be false # @role.sub_roles[0].built_in.should be false
end # end
it 'should have :disabled false' do # it 'should have :disabled false' do
@role.sub_roles[0].disabled.should be false # @role.sub_roles[0].disabled.should be false
end # end
it 'should have a i18n_variable' do # it 'should have a i18n_variable' do
@role.sub_roles[0].i18n_variable.should be_an_instance_of I18nVariable # @role.sub_roles[0].i18n_variable.should be_an_instance_of I18nVariable
end # end
end # end
describe '#AttributeField' do # describe '#AttributeField' do
it 'should have :built_in false' do # it 'should have :built_in false' do
@role.sub_roles[0].attribute_fields[0].built_in.should be false # @role.sub_roles[0].attribute_fields[0].built_in.should be false
end # end
it 'should have :disabled false' do # it 'should have :disabled false' do
@role.sub_roles[0].attribute_fields[0].disabled.should be false # @role.sub_roles[0].attribute_fields[0].disabled.should be false
end # end
end # end
end # end
describe 'Edit role' do # describe 'Edit role' do
describe '#Role' do # describe '#Role' do
before do # before do
@role.update_attributes({:key => 'student', :i18n_variable => {:en => 'Student'}, # @role.update_attributes({:key => 'student', :i18n_variable => {:en => 'Student'},
:sub_roles => [{:key => 'new', # :sub_roles => [{:key => 'new',
:attribute_fields => [{:key => 'bob'}, # :attribute_fields => [{:key => 'bob'},
{:key => 'great'}]}, # {:key => 'great'}]},
{:id => @role.sub_roles[0].id}, # {:id => @role.sub_roles[0].id},
{:id => @role.sub_roles[1].id}]}) # {:id => @role.sub_roles[1].id}]})
end # end
it 'should not be the old :key' do # it 'should not be the old :key' do
@role.key.should_not == 'teacher' # @role.key.should_not == 'teacher'
end # end
it 'should be the new :key' do # it 'should be the new :key' do
@role.key.should == 'student' # @role.key.should == 'student'
end # end
it 'should not be the old :i18n_variable[:en]' do # it 'should not be the old :i18n_variable[:en]' do
@role.i18n_variable[:en].should_not == 'Teacher' # @role.i18n_variable[:en].should_not == 'Teacher'
end # end
it 'should be the new :i18n_variable[:en]' do # it 'should be the new :i18n_variable[:en]' do
@role.i18n_variable[:en].should == 'Student' # @role.i18n_variable[:en].should == 'Student'
end # end
it 'should have one more SubRole' do # it 'should have one more SubRole' do
@role.should have(3).sub_roles # @role.should have(3).sub_roles
end # end
end # end
end # end
describe 'Destroy' do # describe 'Destroy' do
describe '#AttributeField' do # describe '#AttributeField' do
before do # before do
@role.update_attributes(:key => 'teacher', # @role.update_attributes(:key => 'teacher',
:i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'}, # :i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'},
:sub_roles_attributes => {'0' => {:id => @role.sub_roles[0].id, # :sub_roles_attributes => {'0' => {:id => @role.sub_roles[0].id,
:key => 'undergrad', # :key => 'undergrad',
:attribute_fields_attributes => {'0' => {:id => @role.sub_roles[0].attribute_fields[0].id, # :attribute_fields_attributes => {'0' => {:id => @role.sub_roles[0].attribute_fields[0].id,
:key => 'department'}, # :key => 'department'},
'1' => {:id => @role.sub_roles[0].attribute_fields[1].id, # '1' => {:id => @role.sub_roles[0].attribute_fields[1].id,
:key => 'room', :_destroy => true}}}}) # :key => 'room', :_destroy => true}}}})
end # end
it 'should have only one AttributeField for the first SubRole' do # it 'should have only one AttributeField for the first SubRole' do
@role.sub_roles[0].should have(1).attribute_fields # @role.sub_roles[0].should have(1).attribute_fields
end # end
end # end
describe '#I18nVariable' do # describe '#I18nVariable' do
before do # before do
@role.update_attributes(:key => 'teacher', # @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}) # :i18n_variable_attributes => {:id => @role.i18n_variable.id, :key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role', :_destroy => true})
end # end
it 'should not have a I18nVariable' do # it 'should not have a I18nVariable' do
@role.i18n_variable.should_not be_an_instance_of I18nVariable # @role.i18n_variable.should_not be_an_instance_of I18nVariable
end # end
end # end
describe '#Role' do # describe '#Role' do
it 'should destroy the I18nVariable' do # it 'should destroy the I18nVariable' do
id = @role.i18n_variable.id # id = @role.i18n_variable.id
@role.destroy # @role.destroy
lambda {I18nVariable.find(id)}.should raise_error # lambda {I18nVariable.find(id)}.should raise_error
end # end
end # end
end # end
end # end

View File

@ -38,6 +38,7 @@ Spork.prefork do
# automatically. This will be the default behavior in future versions of # automatically. This will be the default behavior in future versions of
# rspec-rails. # rspec-rails.
config.infer_base_class_for_anonymous_controllers = false config.infer_base_class_for_anonymous_controllers = false
end end
end end