rails_dictionary 0.3.pre.rc1 → 0.4.0
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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +33 -0
- data/.gitignore +5 -3
- data/CHANGELOG +19 -3
- data/Gemfile +10 -3
- data/Gemfile.lock +350 -0
- data/{README.v2.0.rdoc → README.rdoc} +33 -15
- data/Rakefile +10 -4
- data/docs/load-order.md +118 -0
- data/lib/rails_dictionary/active_record_extension.rb +48 -0
- data/lib/rails_dictionary/acts_as_dict_slave.rb +85 -0
- data/lib/rails_dictionary/acts_as_dict_type.rb +53 -0
- data/lib/rails_dictionary/acts_as_dictionary.rb +118 -0
- data/lib/rails_dictionary/array_core_ext.rb +10 -0
- data/lib/rails_dictionary/railtie.rb +11 -0
- data/lib/rails_dictionary/version.rb +1 -1
- data/lib/rails_dictionary.rb +64 -20
- data/lib/tasks/dicts.rake +9 -11
- data/pkg/rails_dictionary-0.2.2.gem +0 -0
- data/pkg/rails_dictionary-0.2.3.gem +0 -0
- data/rails_dictionary.gemspec +4 -4
- data/spec/fake_app.rb +29 -0
- data/spec/init_models.rb +12 -0
- data/spec/load_order/empty_boot_recovers.rb +19 -0
- data/spec/load_order/lazy_slave_model_boot.rb +25 -0
- data/spec/load_order/preseeded_boot.rb +22 -0
- data/spec/load_order/support.rb +41 -0
- data/spec/rails_dictionary_spec.rb +172 -0
- data/spec/spec_helper.rb +22 -0
- data/v1.0-roadmap.md +31 -0
- metadata +37 -38
- data/Readme.md +0 -10
- data/lib/rails_dictionary/models/active_record_extension.rb +0 -38
- data/lib/rails_dictionary/models/acts_as_dict_consumer.rb +0 -77
- data/lib/rails_dictionary/models/acts_as_dictionary.rb +0 -27
- data/test/acts_as_consumer_test.rb +0 -44
- data/test/fake_app.rb +0 -40
- data/test/lookup_test.rb +0 -39
- data/test/rails_dictionary_test.rb +0 -81
- data/test/test_helper.rb +0 -36
data/test/fake_app.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# database
|
|
2
|
-
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
|
3
|
-
ActiveRecord::Base.establish_connection(:test)
|
|
4
|
-
|
|
5
|
-
# config
|
|
6
|
-
app = Class.new(Rails::Application)
|
|
7
|
-
app.config.active_support.deprecation = :log
|
|
8
|
-
app.config.eager_load = false
|
|
9
|
-
app.initialize!
|
|
10
|
-
|
|
11
|
-
class Dictionary < ActiveRecord::Base
|
|
12
|
-
acts_as_dictionary
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
class Student < ActiveRecord::Base
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class Lookup < ActiveRecord::Base
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
#migrations
|
|
22
|
-
class CreateAllTables < ActiveRecord::Migration
|
|
23
|
-
def self.up
|
|
24
|
-
create_table(:dictionaries) {|t| t.string :name; t.string :type}
|
|
25
|
-
create_table(:students) do |t|
|
|
26
|
-
t.string :email
|
|
27
|
-
t.integer :city_id
|
|
28
|
-
t.integer :school_id
|
|
29
|
-
t.text :major_array
|
|
30
|
-
t.text :majors
|
|
31
|
-
end
|
|
32
|
-
create_table(:lookups) { |t| t.string :name; t.string :type }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def self.down
|
|
36
|
-
drop_table :dictionaries
|
|
37
|
-
drop_table :students
|
|
38
|
-
drop_table :lookups
|
|
39
|
-
end
|
|
40
|
-
end
|
data/test/lookup_test.rb
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
|
2
|
-
|
|
3
|
-
module TestLookup
|
|
4
|
-
|
|
5
|
-
class TestAsDictionary < TestSupporter
|
|
6
|
-
|
|
7
|
-
def prepare_data
|
|
8
|
-
@art = Lookup.create!(name: 'art', type: 'Lookup::Major')
|
|
9
|
-
@math = Lookup.create!(name: 'math', type: 'Lookup::Major')
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def setup
|
|
13
|
-
RailsDictionary.config.dictionary_klass = :Lookup
|
|
14
|
-
Lookup.acts_as_dictionary
|
|
15
|
-
super
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_lookup
|
|
19
|
-
prepare_data
|
|
20
|
-
assert Lookup, Lookup::Major.superclass
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_student_major_array
|
|
24
|
-
Student.acts_as_dict_consumer on: :major_array, relation_type: :many_to_many, class_name: 'Lookup::Major'
|
|
25
|
-
prepare_data
|
|
26
|
-
s = Student.new(major_array_name: ['art', 'math'])
|
|
27
|
-
s.save!; s.reload
|
|
28
|
-
assert_equal([@art.id, @math.id], s.major_array)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_student_with_majors
|
|
32
|
-
Student.acts_as_dict_consumer on: :majors, relation_type: :many_to_many
|
|
33
|
-
prepare_data
|
|
34
|
-
s = Student.new(majors_name: ['art', 'math'])
|
|
35
|
-
s.save!; s.reload
|
|
36
|
-
assert_equal([@art.id, @math.id], s.majors)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
|
2
|
-
|
|
3
|
-
class TestRailsDictionary < TestSupporter
|
|
4
|
-
|
|
5
|
-
class TestActiveRecordExtension < TestRailsDictionary
|
|
6
|
-
[:acts_as_dictionary, :acts_as_dict_consumer].each do |method_name|
|
|
7
|
-
define_method "test_#{method_name}_exists_ar" do
|
|
8
|
-
assert_includes ActiveRecord::Base.methods, method_name
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class PreTestDatabase < TestRailsDictionary
|
|
14
|
-
|
|
15
|
-
def test_no_dictionary_data_exist_before
|
|
16
|
-
assert_equal 0, Dictionary.count, 'dicionaries table should be blank'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class TestInitSubDictClass < TestRailsDictionary
|
|
21
|
-
def setup
|
|
22
|
-
super
|
|
23
|
-
if Dictionary.const_defined? 'City'
|
|
24
|
-
Dictionary.send :remove_const, 'City'
|
|
25
|
-
RailsDictionary.config.defined_sti_klass.delete('Dictionary::City')
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_dictionary_city_class_when_create_dictionary
|
|
30
|
-
@shanghai = Dictionary.create!(name: "shanghai", type: 'Dictionary::City')
|
|
31
|
-
assert Dictionary, Dictionary::City.superclass
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_dictionary_city_class_when_assign_type
|
|
35
|
-
beijing = Dictionary.new(name: 'beijing')
|
|
36
|
-
beijing.type = 'Dictionary::City'
|
|
37
|
-
beijing.save!
|
|
38
|
-
assert Dictionary, Dictionary::City.superclass
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_dictionary_city_class_when_assign_type_in_new
|
|
42
|
-
beijing = Dictionary.new(name: 'beijing', type: 'Dictionary::City')
|
|
43
|
-
beijing.save!
|
|
44
|
-
assert Dictionary, Dictionary::City.superclass
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
class TestWithDB < TestRailsDictionary
|
|
51
|
-
def setup
|
|
52
|
-
super
|
|
53
|
-
Dictionary.acts_as_dictionary
|
|
54
|
-
@beijing, @shanghai = prepare_city_data
|
|
55
|
-
|
|
56
|
-
@stu_beijing = Student.create! email: "beijing@dict.com", city_id: @shanghai.id
|
|
57
|
-
@stu_shanghai = Student.create! email: "shanghai@dict.com", city_id: @shanghai.id
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
class TestStudent < TestWithDB
|
|
62
|
-
def setup
|
|
63
|
-
super
|
|
64
|
-
Student.acts_as_dict_consumer on: [:city]
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def test_city_name_equal_to_exist_dictionary_name
|
|
68
|
-
assert_equal 1, Dictionary.where(name: "beijing").count
|
|
69
|
-
@stu_shanghai.update_attributes city_name: "beijing"
|
|
70
|
-
assert_equal 'beijing', @stu_shanghai.reload.city.name
|
|
71
|
-
assert_equal 1, Dictionary.where(name: "beijing").count
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def create_a_student_with_shanghai_city
|
|
75
|
-
s = Student.create(city_name: "shanghai")
|
|
76
|
-
s.reload
|
|
77
|
-
s.city.name.should == "shanghai"
|
|
78
|
-
assert_equal Dictionary.find_by(name: 'shanghai').id, s.city_id
|
|
79
|
-
assert_equal 1, Dictionary.where(name: "shanghai").count
|
|
80
|
-
end
|
|
81
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# copy and modify the test design of kaminari(a paginate gem for Rails3)
|
|
2
|
-
RAILS_ENV = 'test'
|
|
3
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
5
|
-
require 'byebug'
|
|
6
|
-
require 'rack/test'
|
|
7
|
-
require 'rails'
|
|
8
|
-
require 'active_record'
|
|
9
|
-
require 'rails_dictionary'
|
|
10
|
-
|
|
11
|
-
ActiveRecord::Migration.verbose = false
|
|
12
|
-
|
|
13
|
-
require File.join(File.dirname(__FILE__), 'fake_app')
|
|
14
|
-
|
|
15
|
-
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'dictionaries'
|
|
16
|
-
|
|
17
|
-
Student.serialize :major_array, Array
|
|
18
|
-
Student.serialize :majors, Array
|
|
19
|
-
|
|
20
|
-
require 'minitest/autorun'
|
|
21
|
-
require 'database_cleaner'
|
|
22
|
-
|
|
23
|
-
DatabaseCleaner.strategy = :truncation
|
|
24
|
-
|
|
25
|
-
class TestSupporter < Minitest::Test
|
|
26
|
-
def setup
|
|
27
|
-
DatabaseCleaner.clean
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def prepare_city_data
|
|
31
|
-
[
|
|
32
|
-
Dictionary.create!(name: 'beijing', type: 'Dictionary::City'),
|
|
33
|
-
Dictionary.create!(name: 'shanghai', type: 'Dictionary::City')
|
|
34
|
-
]
|
|
35
|
-
end
|
|
36
|
-
end
|