| 
									
										
										
										
											2012-11-03 21:56:29 +00:00
										 |  |  | #encoding: UTF-8 | 
					
						
							|  |  |  | require 'spec_helper' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe AttributeValue do | 
					
						
							|  |  |  |   describe "#attribute_value" do | 
					
						
							| 
									
										
										
										
											2012-11-08 10:59:19 +00:00
										 |  |  |     context "Date should render out right value"  | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         @user = User.where(email:'chris@rulingcom.com').first | 
					
						
							|  |  |  |         @af = AttributeField.last | 
					
						
							|  |  |  |         @af.markup = "date" | 
					
						
							|  |  |  |         @af.save | 
					
						
							|  |  |  |         @av = @user.attribute_values.build :attribute_field=>@af | 
					
						
							|  |  |  |       end # of before | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "should be 民前 1年" do | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         @av.value = {"(1i)"=>"1911", "(2i)"=>"11", "(3i)"=>"6"} | 
					
						
							|  |  |  |         binding.pry | 
					
						
							|  |  |  |         @av.get_value_by_locale("zh_tw").should match /^民前.*/ | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "should be 民國元年" do | 
					
						
							|  |  |  |         @av.value = {"(1i)"=>"1912", "(2i)"=>"11", "(3i)"=>"6"} | 
					
						
							|  |  |  |         @av.get_value_by_locale("zh_tw").should "民國元年" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "should be 民國 75年" do | 
					
						
							|  |  |  |         @av.value ={"(1i)"=>"1913", "(2i)"=>"11", "(3i)"=>"6"} | 
					
						
							|  |  |  |         @av.get_value_by_locale("zh_tw").should match /^民國.*/ | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-03 21:56:29 +00:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2012-11-08 10:59:19 +00:00
										 |  |  |             pending | 
					
						
							|  |  |  |             # @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 | 
					
						
							| 
									
										
										
										
											2012-11-03 21:56:29 +00:00
										 |  |  |               # @av.destroy | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           it "[#{markup[0]}]Output(just for show): should output data at right way when local is set to #{locale_sat}" do | 
					
						
							| 
									
										
										
										
											2012-11-08 10:59:19 +00:00
										 |  |  |             pending | 
					
						
							|  |  |  |             # 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 | 
					
						
							| 
									
										
										
										
											2012-11-03 21:56:29 +00:00
										 |  |  |           end | 
					
						
							|  |  |  |            | 
					
						
							|  |  |  |       end #end of LIST loop | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |