dm-reflection 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+ require 'dm-reflection/builders/source_builder'
3
+
4
+ PERSON = <<-RUBY
5
+ class Person
6
+
7
+ include DataMapper::Resource
8
+
9
+ property :id, Serial
10
+
11
+ property :name, String, :required => true, :length => 200
12
+ property :email, String, :required => true, :unique => true, :unique_index => true
13
+ property :created_at, DateTime
14
+ property :updated_at, DateTime
15
+
16
+ has 1, :profile
17
+ has n, :projects, :through => Resource
18
+
19
+ end
20
+ RUBY
21
+
22
+ PROFILE = <<-RUBY
23
+ class Profile
24
+
25
+ include DataMapper::Resource
26
+
27
+ property :id, Serial
28
+
29
+ property :person_id, Integer, :required => true, :min => 1
30
+ property :nickname, String
31
+ property :image, String
32
+ property :created_at, DateTime
33
+ property :updated_at, DateTime
34
+
35
+ belongs_to :person
36
+
37
+ end
38
+ RUBY
39
+
40
+ PROJECT = <<-RUBY
41
+ class Project
42
+
43
+ include DataMapper::Resource
44
+
45
+ property :id, Serial
46
+
47
+ property :name, String, :required => true, :length => 200
48
+ property :created_at, DateTime
49
+ property :updated_at, DateTime
50
+
51
+ has n, :project_tasks
52
+ has n, :tasks, :through => :project_tasks
53
+ has 1..n, :people, :through => Resource
54
+
55
+ end
56
+ RUBY
57
+
58
+ TASK = <<-RUBY
59
+ class Task
60
+
61
+ include DataMapper::Resource
62
+
63
+ property :id, Serial
64
+
65
+ property :name, String, :required => true, :length => 200
66
+ property :email, String, :required => true, :unique => true, :unique_index => true
67
+ property :created_at, DateTime
68
+ property :updated_at, DateTime
69
+
70
+ has n, :project_tasks
71
+ has n, :projects, :through => :project_tasks
72
+
73
+ end
74
+ RUBY
75
+
76
+ PROJECT_TASK = <<-RUBY
77
+ class ProjectTask
78
+
79
+ include DataMapper::Resource
80
+
81
+ property :project_id, Integer, :key => true, :min => 1
82
+ property :task_id, Integer, :key => true, :min => 1
83
+
84
+ property :created_at, DateTime
85
+ property :updated_at, DateTime
86
+
87
+ belongs_to :project
88
+ belongs_to :task
89
+
90
+ end
91
+ RUBY
92
+
93
+ SOURCES = [ PERSON, PROFILE, PROJECT, TASK, PROJECT_TASK ]
94
+
95
+ describe DataMapper::Reflection::Builders::Source::Model do
96
+
97
+ before(:all) do
98
+
99
+ SOURCES.each { |source| eval(source) }
100
+
101
+ @models = {
102
+ Person => PERSON,
103
+ Profile => PROFILE,
104
+ Project => PROJECT,
105
+ Task => TASK,
106
+ ProjectTask => PROJECT_TASK
107
+ }
108
+
109
+ end
110
+
111
+ it "should behave like datamapper when the relation is not in 1NF (raise DataMapper::IncompleteModelError)" do
112
+ invalid_resource = Class.new { include DataMapper::Resource }
113
+ lambda { invalid_resource.to_ruby }.should raise_error(DataMapper::IncompleteModelError)
114
+ end
115
+
116
+ it 'should return a proper datamapper model definition' do
117
+
118
+ @models.each_pair do |model, source|
119
+
120
+ # puts '-'*80
121
+ # puts model.to_ruby
122
+ # puts '-'*80
123
+
124
+ model.to_ruby.should == source
125
+
126
+ end
127
+
128
+ end
129
+
130
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --loadby random
3
+ --format specdoc
4
+ --backtrace
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
5
+
6
+ require 'dm-core'
7
+ require 'dm-reflection'
8
+
9
+ require 'spec'
10
+ require 'spec/autorun'
11
+
12
+ ENV["SQLITE3_SPEC_URI"] ||= 'sqlite3::memory:'
13
+ ENV["MYSQL_SPEC_URI"] ||= 'mysql://localhost/dm-reflections_test'
14
+ ENV["POSTGRES_SPEC_URI"] ||= 'postgres://postgres@localhost/dm-reflection_test'
15
+ ENV["PERSEVERE_SPEC_URI"] ||= 'persevere://localhost:8080/'
16
+
17
+ def setup_adapter(name, default_uri = nil)
18
+ begin
19
+ DataMapper.setup(name, ENV["#{ENV['ADAPTER'].to_s.upcase}_SPEC_URI"] || default_uri)
20
+ Object.const_set('ADAPTER', ENV['ADAPTER'].to_sym) if name.to_s == ENV['ADAPTER']
21
+ true
22
+ rescue Exception => e
23
+ if name.to_s == ENV['ADAPTER']
24
+ Object.const_set('ADAPTER', nil)
25
+ warn "Could not load do_#{name}: #{e}"
26
+ end
27
+ false
28
+ end
29
+ end
30
+
31
+ ENV['ADAPTER'] ||= 'persevere'
32
+ setup_adapter(:default)
33
+
34
+ Spec::Runner.configure do |config|
35
+
36
+ end
37
+
38
+ def remove_model_from_memory(model)
39
+ DataMapper::Model.descendants.delete(model)
40
+ Object.send(:remove_const, model.name.to_sym)
41
+ end
@@ -0,0 +1,20 @@
1
+ require 'time'
2
+
3
+ desc 'update changelog'
4
+ task :changelog do
5
+ File.open('CHANGELOG', 'w+') do |changelog|
6
+ `git log -z --abbrev-commit`.split("\0").each do |commit|
7
+ next if commit =~ /^Merge: \d*/
8
+ ref, author, time, _, title, _, message = commit.split("\n", 7)
9
+ ref = ref[/commit ([0-9a-f]+)/, 1]
10
+ author = author[/Author: (.*)/, 1].strip
11
+ time = Time.parse(time[/Date: (.*)/, 1]).utc
12
+ title.strip!
13
+
14
+ changelog.puts "[#{ref} | #{time}] #{author}"
15
+ changelog.puts '', " * #{title}"
16
+ changelog.puts '', message.rstrip if message
17
+ changelog.puts
18
+ end
19
+ end
20
+ end
data/tasks/ci.rake ADDED
@@ -0,0 +1 @@
1
+ task :ci => [ :verify_measurements, 'metrics:all' ]
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'metric_fu'
3
+ rescue LoadError
4
+ namespace :metrics do
5
+ task :all do
6
+ abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
7
+ end
8
+ end
9
+ end
10
+
11
+ begin
12
+ require 'reek/adapters/rake_task'
13
+
14
+ Reek::RakeTask.new do |t|
15
+ t.fail_on_error = true
16
+ t.verbose = false
17
+ t.source_files = 'lib/**/*.rb'
18
+ end
19
+ rescue LoadError
20
+ task :reek do
21
+ abort 'Reek is not available. In order to run reek, you must: gem install reek'
22
+ end
23
+ end
24
+
25
+ begin
26
+ require 'roodi'
27
+ require 'roodi_task'
28
+
29
+ RoodiTask.new do |t|
30
+ t.verbose = false
31
+ end
32
+ rescue LoadError
33
+ task :roodi do
34
+ abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
35
+ end
36
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,25 @@
1
+ require 'spec/rake/spectask'
2
+ require 'spec/rake/verify_rcov'
3
+
4
+ spec_defaults = lambda do |spec|
5
+ spec.pattern = 'spec/**/*_spec.rb'
6
+ spec.libs << 'lib' << 'spec'
7
+ spec.spec_opts << '--options' << 'spec/spec.opts'
8
+ end
9
+
10
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
11
+
12
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
13
+ spec_defaults.call(rcov)
14
+ rcov.rcov = true
15
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
16
+ end
17
+
18
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
19
+ rcov.threshold = 100
20
+ end
21
+
22
+ task :spec => :check_dependencies
23
+ task :rcov => :check_dependencies
24
+
25
+ task :default => :spec
data/tasks/yard.rake ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new
5
+ rescue LoadError
6
+ task :yard do
7
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'pathname'
3
+ require 'yardstick/rake/measurement'
4
+ require 'yardstick/rake/verify'
5
+
6
+ # yardstick_measure task
7
+ Yardstick::Rake::Measurement.new
8
+
9
+ # verify_measurements task
10
+ Yardstick::Rake::Verify.new do |verify|
11
+ verify.threshold = 100
12
+ end
13
+ rescue LoadError
14
+ %w[ yardstick_measure verify_measurements ].each do |name|
15
+ task name.to_s do
16
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-reflection
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 5
9
+ version: 0.0.5
10
+ platform: ruby
11
+ authors:
12
+ - Martin Gamsjaeger (snusnu), Yogo Team
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-03 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: dm-core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 10
30
+ - 2
31
+ version: 0.10.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 3
44
+ version: "1.3"
45
+ type: :development
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 5
57
+ version: "0.5"
58
+ type: :development
59
+ version_requirements: *id003
60
+ description: Generates datamapper models from existing database schemas and export them to files
61
+ email: irjudson@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - LICENSE
68
+ - README.rdoc
69
+ files:
70
+ - .document
71
+ - .gitignore
72
+ - LICENSE
73
+ - README.rdoc
74
+ - Rakefile
75
+ - VERSION
76
+ - dm-reflection.gemspec
77
+ - lib/dm-reflection.rb
78
+ - lib/dm-reflection/adapters/mysql.rb
79
+ - lib/dm-reflection/adapters/persevere.rb
80
+ - lib/dm-reflection/adapters/postgres.rb
81
+ - lib/dm-reflection/adapters/sqlite3.rb
82
+ - lib/dm-reflection/builders/source_builder.rb
83
+ - lib/dm-reflection/reflection.rb
84
+ - lib/dm-reflection/version.rb
85
+ - spec/persevere_reflection_spec.rb
86
+ - spec/rcov.opts
87
+ - spec/reflection_spec.rb
88
+ - spec/source_builder_spec.rb
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ - tasks/changelog.rake
92
+ - tasks/ci.rake
93
+ - tasks/metrics.rake
94
+ - tasks/spec.rake
95
+ - tasks/yard.rake
96
+ - tasks/yardstick.rake
97
+ has_rdoc: true
98
+ homepage: http://github.com/irjudson/dm-reflection
99
+ licenses: []
100
+
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --charset=UTF-8
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.6
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Generates datamapper models from existing database schemas
127
+ test_files:
128
+ - spec/persevere_reflection_spec.rb
129
+ - spec/reflection_spec.rb
130
+ - spec/source_builder_spec.rb
131
+ - spec/spec_helper.rb