rails_dictionary 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -103,7 +103,7 @@ In short,when you confused with the debug data,try running "rails tmp:clear" fir
103
103
 
104
104
  = TODO & Problems
105
105
  There are no convention and implemention to map Class like Ckeditor::Asset to a method.
106
- Add generators.
106
+ Add generators. Rewrite Testing,make it more maintainable.
107
107
 
108
108
  = Help
109
109
  Need an friendly english native guy to help me improve this readme to make it more clear and readable.
@@ -9,7 +9,15 @@ module ActsAsDictionary
9
9
  belongs_to :dict_type
10
10
  after_save :delete_dicts_cache
11
11
  after_destroy :delete_dicts_cache
12
- scope :dict_type_name_eq,lambda {|method_name| joins(:dict_type).where("dict_types.name" => method_name).all}
12
+
13
+ # Return an instance of array
14
+ def dict_type_name_eq(method_name)
15
+ joins(:dict_type).where("dict_types.name" => method_name).all
16
+ end
17
+ #Following design is not successed with sqlite3 in test
18
+ # scope :dict_type_name_eq,lambda {|method_name| joins(:dict_type).where("dict_types.name" => method_name)}
19
+ # remove the all seems not pass test,return following errors
20
+ # TypeError: no marshal_dump is defined for class SQLite3::Database
13
21
  include InstanceMethods
14
22
  # Generate methods like Dictionary.student_city
15
23
  # Dictionary.student_city - a list of dictionary object which dict type is student_city
@@ -19,8 +27,9 @@ module ActsAsDictionary
19
27
  def self.method_missing(method_id,options={},&block)
20
28
  method_name=method_id.to_s.downcase
21
29
  if DictType.all_types.include? method_id.to_s
22
- Rails.cache.fetch("Dictionary.#{method_name}") { Dictionary.dict_type_name_eq(method_name) }
30
+ Rails.cache.fetch("Dictionary.#{method_name}") { dict_type_name_eq(method_name) }
23
31
  listed_attr=Rails.cache.read("Dictionary.#{method_name}").dup
32
+ # Instance of activerelation can not be dup?
24
33
  if options.keys.include? :locale or options.keys.include? "locale"
25
34
  locale="name_#{ options[:locale] }"
26
35
  listed_attr.map! { |a| [a.send(locale),a.id] }
@@ -1,3 +1,3 @@
1
1
  module RailsDictionary
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -95,14 +95,6 @@ class DictTypeTest < Test::Unit::TestCase
95
95
  assert_equal "student_school",DictType.revert(@dt_stu_school.id)
96
96
  end
97
97
 
98
- def test_dictionary_method_missing
99
- assert_equal [["shanghai",1],["beijing",2]],Dictionary.student_city(:locale => :en)
100
- end
101
-
102
- def test_dictionary_method_missing_with_locale
103
- assert_equal [["上海", 1], ["北京", 2]],Dictionary.student_city(:locale => :zh)
104
- end
105
-
106
98
  # test dynamic instance methods in slave model
107
99
  def test_named_city
108
100
  Student.acts_as_dict_slave
@@ -119,6 +111,14 @@ class DictTypeTest < Test::Unit::TestCase
119
111
  assert_equal "Pékin",@stu_beijing.named_city
120
112
  end
121
113
 
114
+ def test_dictionary_method_missing
115
+ assert_equal [["shanghai",1],["beijing",2]],Dictionary.student_city(:locale => :en)
116
+ end
117
+
118
+ def test_dictionary_method_missing_with_locale
119
+ assert_equal [["上海", 1], ["北京", 2]],Dictionary.student_city(:locale => :zh)
120
+ end
121
+
122
122
  def test_delete_dicts_cache
123
123
  @dy_wuhan=Dictionary.create! name_en: "wuhan",name_zh: "武汉",name_fr: "wuhan",dict_type_id: @dt_stu_city.id
124
124
  assert_equal [["shanghai", 1], ["beijing", 2], ["wuhan", 3]],Dictionary.student_city(:locale => :en)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails_dictionary
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - raykin