delineate 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ #require 'bundler/setup'
6
+ #Bundler.require
7
+
8
+ #require 'simplecov'
9
+ #SimpleCov.start
10
+
11
+ ENV['RAILS_ENV'] = 'test'
12
+
13
+ require 'active_support'
14
+ require 'active_support/core_ext/logger'
15
+ require 'active_record'
16
+
17
+ require 'rspec'
18
+
19
+ require 'delineate'
20
+
21
+
22
+ # Requires supporting files with custom matchers and macros, etc,
23
+ # in ./support/ and its subdirectories.
24
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
25
+
26
+ RSpec.configure do |config|
27
+ end
28
+
29
+ # a little sugar for checking results of a section of code
30
+ alias :running :lambda
31
+
32
+
33
+ # Set the DB var if testing with other than sqlite
34
+ ENV['DB'] ||= 'sqlite3'
35
+
36
+ database_yml = File.expand_path('../database.yml', __FILE__)
37
+ if File.exists?(database_yml)
38
+ active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
39
+
40
+ ActiveRecord::Base.establish_connection(active_record_configuration)
41
+ ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "test.log"))
42
+ #ActiveRecord::Base.logger = Logger.new(STDOUT)
43
+
44
+ ActiveRecord::Base.silence do
45
+ ActiveRecord::Migration.verbose = false
46
+
47
+ load(File.dirname(__FILE__) + '/support/schema.rb')
48
+ create_schema!
49
+
50
+ load(File.dirname(__FILE__) + '/support/models.rb')
51
+ clean_database!
52
+ end
53
+ else
54
+ raise "Create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
55
+ end
@@ -0,0 +1,184 @@
1
+ # Contains ActiveRecord model test classes
2
+
3
+ class Post < ActiveRecord::Base
4
+ end
5
+ class Author < ActiveRecord::Base
6
+ end
7
+ #class Comment < ActiveRecord::Base
8
+ #end
9
+ #class Reply < Comment
10
+ #end
11
+ class Topic < ActiveRecord::Base
12
+ end
13
+ class AuthorGroup < ActiveRecord::Base
14
+ end
15
+ class Email < ActiveRecord::Base
16
+ end
17
+
18
+ class PostTopic < ActiveRecord::Base
19
+ belongs_to :post
20
+ belongs_to :topic
21
+ has_one :author, :through => :post
22
+ end
23
+
24
+ class Comment < ActiveRecord::Base
25
+ belongs_to :post
26
+ accepts_nested_attributes_for :post
27
+
28
+ attr_accessible :commentor, :content, :post, :post_attributes, :post_id
29
+
30
+ map_attributes :api do
31
+ attribute :id
32
+ attribute :commentor
33
+ attribute :content
34
+ attribute :created_at, :access => :ro
35
+
36
+ association :post, :optional => true
37
+ end
38
+ end
39
+
40
+ class Reply < Comment
41
+ attr_accessible :type
42
+
43
+ map_attributes :api do
44
+ attribute :type
45
+ end
46
+ end
47
+
48
+ class Post < ActiveRecord::Base
49
+ belongs_to :author
50
+ has_many :post_topics
51
+ has_many :topics, :through => :post_topics
52
+ has_many :comments
53
+
54
+ accepts_nested_attributes_for :author, :allow_destroy => true
55
+ accepts_nested_attributes_for :post_topics
56
+ accepts_nested_attributes_for :topics, :allow_destroy => false
57
+ accepts_nested_attributes_for :comments, :allow_destroy => true
58
+
59
+ attr_accessible :title, :content, :author, :author_attributes, :post_topics, :post_topics_attributes, :comments, :comments_attributes
60
+ attr_accessible :topics, :topics_attributes
61
+
62
+ map_attributes :api do
63
+ attribute :id
64
+ attribute :title
65
+ attribute :content
66
+ attribute :created_at, :access => :ro
67
+
68
+ attribute :heavy_attr, :access => :ro, :optional => :extended_attrs
69
+
70
+ association :author, :override => :merge do
71
+ attribute :name, :using => :full_name, :access => :ro
72
+ end
73
+
74
+ association :topics
75
+ association :comments, :optional => true, :polymorphic => true
76
+ end
77
+
78
+ def heavy_attr
79
+ true
80
+ end
81
+ end
82
+
83
+ class Author < ActiveRecord::Base
84
+ belongs_to :author_group
85
+ has_many :posts
86
+ has_many :post_topics, :through => :posts
87
+ has_one :email
88
+
89
+ accepts_nested_attributes_for :author_group
90
+ accepts_nested_attributes_for :posts
91
+ accepts_nested_attributes_for :email, :allow_destroy => true
92
+
93
+ attr_accessible :first_name, :last_name, :full_name, :email_attributes, :posts_attributes, :author_group, :author_group_attributes
94
+
95
+ scope :by_topic, lambda {|topic_id| joins(:post_topics).where(:topic_id => topic_id)}
96
+
97
+ map_attributes :api do
98
+ attribute :id
99
+ attribute :first_name
100
+ attribute :last_name
101
+
102
+ association :email, :polymorphic => true
103
+ association :posts, :optional => true, :override => :replace do
104
+ attribute :id
105
+ attribute :title
106
+ attribute :content
107
+ attribute :created_at, :access => :ro
108
+ end
109
+ #association :posts_circular, :using => :posts, :optional => true # This should generate "circular merge" error when included
110
+ association :author_group, :optional => true
111
+ end
112
+
113
+ def full_name
114
+ "#{first_name} #{last_name}"
115
+ end
116
+
117
+ def topics
118
+ post_topics.map{|pt| pt.topic.name}.uniq
119
+ end
120
+ end
121
+
122
+ class Email < ActiveRecord::Base
123
+ belongs_to :author
124
+
125
+ attr_accessible :email_addr, :author_id
126
+
127
+ map_attributes :api do
128
+ attribute :id
129
+ attribute :email, :using => :email_addr
130
+ end
131
+ end
132
+
133
+ class SpecialEmail < Email
134
+ attr_accessible :special_email
135
+
136
+ map_attributes :api do
137
+ attribute :special_email
138
+ end
139
+
140
+ def special_email
141
+ 'special'
142
+ end
143
+ end
144
+
145
+
146
+ class Topic < ActiveRecord::Base
147
+ has_many :post_topics
148
+ has_many :posts, :through => :post_topics
149
+
150
+ attr_accessible :name
151
+
152
+ map_attributes :api do
153
+ attribute :id
154
+ attribute :topic, :using => :name
155
+ end
156
+ end
157
+
158
+ class AuthorGroup < ActiveRecord::Base
159
+ has_many :authors
160
+
161
+ accepts_nested_attributes_for :authors
162
+ attr_accessible :name, :authors_attributes
163
+
164
+ map_attributes :api do
165
+ attribute :id
166
+ attribute :name
167
+ association :authors, :optional => true
168
+ end
169
+ end
170
+
171
+
172
+
173
+ # Used to reinitialize class defintions
174
+ def reload_model_classes!
175
+ Object.send(:remove_const, :Post)
176
+ Object.send(:remove_const, :Author)
177
+ Object.send(:remove_const, :Reply)
178
+ Object.send(:remove_const, :Comment)
179
+ Object.send(:remove_const, :Topic)
180
+ Object.send(:remove_const, :AuthorGroup)
181
+ Object.send(:remove_const, :PostTopic)
182
+
183
+ load __FILE__
184
+ end
@@ -0,0 +1,125 @@
1
+ # Support for creating the test schema and seed data
2
+
3
+ def create_schema!
4
+ ActiveRecord::Schema.define :version => 0 do
5
+ create_table "posts", :force => true do |t|
6
+ t.string :title
7
+ t.text :content
8
+ t.references :author, :null => :false
9
+ t.datetime :created_at
10
+ end
11
+
12
+ create_table "authors", :force => true do |t|
13
+ t.string :first_name
14
+ t.string :last_name
15
+ t.references :author_group
16
+ end
17
+
18
+ create_table "comments", :force => true do |t|
19
+ t.string :commentor
20
+ t.references :post
21
+ t.text :content
22
+ t.string :type
23
+ t.datetime :created_at
24
+ end
25
+
26
+ create_table "topics", :force => true do |t|
27
+ t.string :name
28
+ end
29
+
30
+ create_table "post_topics", :force => true do |t|
31
+ t.references :topic
32
+ t.references :post
33
+ end
34
+
35
+ create_table "author_groups", :force => true do |t|
36
+ t.string :name
37
+ end
38
+
39
+ create_table "emails", :force => true do |t|
40
+ t.string :email_addr
41
+ t.references :author
42
+ t.string :type
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ def clean_database!
49
+ seed_author_groups
50
+ seed_authors
51
+ seed_emails
52
+ seed_topics
53
+ seed_posts
54
+ seed_post_topics
55
+ seed_comments
56
+ end
57
+
58
+ def seed_author_groups
59
+ ActiveRecord::Base.connection.execute "DELETE FROM author_groups"
60
+ AuthorGroup.create!(:name => 'Admin') # 1
61
+ AuthorGroup.create!(:name => 'Staff') # 2
62
+ AuthorGroup.create!(:name => 'Guest') # 3
63
+ end
64
+
65
+ def seed_authors
66
+ ActiveRecord::Base.connection.execute "DELETE FROM authors"
67
+ Author.create!(:first_name => 'Tom', :last_name => 'Smith', :author_group => AuthorGroup.find_by_name('Admin'))
68
+ Author.create!(:first_name => 'John', :last_name => 'Staffer', :author_group => AuthorGroup.find_by_name('Staff'))
69
+ Author.create!(:first_name => 'John', :last_name => 'Smith', :author_group => AuthorGroup.find_by_name('Staff'))
70
+ Author.create!(:first_name => 'John', :last_name => 'Public', :author_group => AuthorGroup.find_by_name('Guest'))
71
+ Author.create!(:first_name => 'Mary', :last_name => 'Jones', :author_group => AuthorGroup.find_by_name('Staff'))
72
+ Author.create!(:first_name => 'Julie', :last_name => 'Smith', :author_group => AuthorGroup.find_by_name('Guest'))
73
+ end
74
+
75
+ def seed_emails
76
+ Email.create!(:author_id => 1, :email_addr => 'author1@email.com')
77
+ Email.create!(:author_id => 2, :email_addr => 'author2@email.com')
78
+ Email.create!(:author_id => 3, :email_addr => 'author3@email.com')
79
+ Email.create!(:author_id => 4, :email_addr => 'author4@email.com')
80
+ SpecialEmail.create!(:author_id => 5, :email_addr => 'author5@email.com')
81
+ end
82
+
83
+ def seed_topics
84
+ ActiveRecord::Base.connection.execute "DELETE FROM topics"
85
+ Topic.create!(:name => 'NoSQL') # 1
86
+ Topic.create!(:name => 'Ruby') # 2
87
+ Topic.create!(:name => 'Rails') # 3
88
+ Topic.create!(:name => 'Events') # 4
89
+ Topic.create!(:name => 'General') # 5
90
+ end
91
+
92
+ def seed_posts
93
+ Post.create!(:title => "Post Number 1" , :content => "This is the content for post 1" , :author => Author.find(1))
94
+ Post.create!(:title => "Post Number 2" , :content => "This is the content for post 2" , :author => Author.find(2))
95
+ Post.create!(:title => "Post Number 3" , :content => "This is the content for post 3" , :author => Author.find(3))
96
+ Post.create!(:title => "Post Number 4" , :content => "This is the content for post 4" , :author => Author.find(4))
97
+ Post.create!(:title => "Post Number 5" , :content => "This is the content for post 5" , :author => Author.find(5))
98
+
99
+ Post.create!(:title => "Post Number 6" , :content => "This is the content for post 6" , :author => Author.find(1))
100
+ Post.create!(:title => "Post Number 7" , :content => "This is the content for post 7" , :author => Author.find(1))
101
+ end
102
+
103
+ def seed_post_topics
104
+ PostTopic.create!(:topic => Topic.find_by_name('NoSQL'), :post_id => 1)
105
+ PostTopic.create!(:topic => Topic.find_by_name('Events'), :post_id => 1)
106
+
107
+ PostTopic.create!(:topic => Topic.find_by_name('NoSQL'), :post_id => 2)
108
+ PostTopic.create!(:topic => Topic.find_by_name('Ruby'), :post_id => 3)
109
+ PostTopic.create!(:topic => Topic.find_by_name('Rails'), :post_id => 4)
110
+ PostTopic.create!(:topic => Topic.find_by_name('Events'), :post_id => 5)
111
+ PostTopic.create!(:topic => Topic.find_by_name('General'), :post_id => 6)
112
+ PostTopic.create!(:topic => Topic.find_by_name('Ruby'), :post_id => 7)
113
+ PostTopic.create!(:topic => Topic.find_by_name('Rails'), :post_id => 7)
114
+ end
115
+
116
+ def seed_comments
117
+ Comment.create!(:commentor => 'Anonymous', :post_id => 1, :content => 'Comment 1 for post 1')
118
+ Comment.create!(:commentor => 'commentor1', :post_id => 1, :content => 'Comment 2 for post 1')
119
+ Comment.create!(:commentor => 'commentor2', :post_id => 2, :content => 'Comment 1 for post 2')
120
+ Comment.create!(:commentor => 'commentor3', :post_id => 3, :content => 'Comment 1 for post 3')
121
+ Comment.create!(:commentor => 'commentor7', :post_id => 7, :content => 'Comment 1 for post 7')
122
+ Comment.create!(:commentor => 'commentor8', :post_id => 7, :content => 'Comment 2 for post 7')
123
+
124
+ Reply.create!(:commentor => 'commentor1', :post_id => 1, :content => 'Reply to Comment for post 1')
125
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delineate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ version_requirements: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: '3.2'
19
+ prerelease: false
20
+ name: activerecord
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: '3.2'
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ prerelease: false
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2.14'
47
+ prerelease: false
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '3.12'
61
+ prerelease: false
62
+ name: rdoc
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '3.12'
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '1'
75
+ prerelease: false
76
+ name: bundler
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '1'
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '2.0'
89
+ prerelease: false
90
+ name: jeweler
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '2.0'
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ prerelease: false
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ - !ruby/object:Gem::Dependency
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ~>
115
+ - !ruby/object:Gem::Version
116
+ version: '1'
117
+ prerelease: false
118
+ name: sqlite3
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ~>
122
+ - !ruby/object:Gem::Version
123
+ version: '1'
124
+ type: :development
125
+ description: ActiveRecord serializer DSL for mapping model attributes and associations.
126
+ Similar to ActiveModel Serializers with many enhancements including bi-directional
127
+ support, i.e. deserialization.
128
+ email: tsmith@landfall.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ files:
135
+ - .document
136
+ - .rspec
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.rdoc
141
+ - Rakefile
142
+ - VERSION
143
+ - delineate.gemspec
144
+ - lib/class_inheritable_attributes.rb
145
+ - lib/core_extensions.rb
146
+ - lib/delineate.rb
147
+ - lib/delineate/attribute_map/attribute_map.rb
148
+ - lib/delineate/attribute_map/csv_serializer.rb
149
+ - lib/delineate/attribute_map/json_serializer.rb
150
+ - lib/delineate/attribute_map/map_serializer.rb
151
+ - lib/delineate/attribute_map/xml_serializer.rb
152
+ - lib/delineate/map_attributes.rb
153
+ - spec/database.yml
154
+ - spec/delineate_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/models.rb
157
+ - spec/support/schema.rb
158
+ homepage: http://github.com/rtomsmith/delineate
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.2.2
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: ActiveRecord serializer DSL for mapping model attributes and associations
182
+ test_files: []