conventional_models 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  module ConventionalModels
4
- describe Conventions do
4
+ describe Config do
5
5
  it "should set ignored tables" do
6
- config = Conventions.new do
6
+ config = Config.new do
7
7
  ignore_tables "slc", "abc"
8
8
  end
9
9
  config.ignored_tables.should == ["slc", "abc"]
10
10
  end
11
11
 
12
12
  it "should set primary key name" do
13
- config = Conventions.new do
13
+ config = Config.new do
14
14
  primary_key_name "Id"
15
15
  end
16
16
  config.primary_key_name.should == "Id"
17
17
  end
18
18
 
19
19
  it "should set belongs to matcher" do
20
- config = Conventions.new do
20
+ config = Config.new do
21
21
  belongs_to_matcher do |column|
22
22
  true
23
23
  end
@@ -26,7 +26,7 @@ module ConventionalModels
26
26
  end
27
27
 
28
28
  it "should set belongs to name" do
29
- config = Conventions.new do
29
+ config = Config.new do
30
30
  belongs_to_name do |column|
31
31
  column
32
32
  end
@@ -35,18 +35,32 @@ module ConventionalModels
35
35
  end
36
36
 
37
37
  it "should set class name" do
38
- config = Conventions.new do
38
+ config = Config.new do
39
39
  class_name do |column|
40
40
  "test"
41
41
  end
42
42
  end
43
43
  config.class_name.call("").should == "test"
44
44
  end
45
+
46
+ it "should set connection" do
47
+ config = Config.new do
48
+ connection :adapter => 'sqlite3'
49
+ end
50
+ config.connection[:adapter].should == 'sqlite3'
51
+ end
52
+
53
+ it "should set module name" do
54
+ config = Config.new do
55
+ module_name "test"
56
+ end
57
+ config.module_name.should == "test"
58
+ end
45
59
 
46
60
  it "should have default settings" do
47
61
  @site_id_column = Column.new("site_id", nil, "integer")
48
62
 
49
- config = Conventions.new
63
+ config = Config.new
50
64
  config.belongs_to_name.call(@site_id_column).should == "site"
51
65
  config.belongs_to_matcher.call(@site_id_column).should be_true
52
66
  config.primary_key_name.should == "id"
@@ -2,44 +2,36 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  module ConventionalModels
4
4
  describe Database do
5
- before(:each) do
6
- @conventions = mock(Conventions)
7
- @conventions.stub(:ignored_tables).and_return([])
8
-
9
- @connection = mock(::ActiveRecord::ConnectionAdapters::AbstractAdapter)
10
- @columns = [mock(Column)]
11
-
12
- ::ActiveRecord::Base.stub(:connection).and_return(@connection)
13
-
14
- @connection.stub(:tables).and_return(["Test"])
15
- @connection.stub(:columns).with("Test").and_return(@columns)
16
-
17
- @table = mock(Table)
18
- @table.stub(:apply_conventions)
19
- @table.stub(:belongs_to_names).and_return([])
20
- @table.stub(:name).and_return("Test")
21
- Table.stub(:new => @table)
5
+ let(:table) { mock(Table, :apply_conventions => nil, :belongs_to_names => [], :name => "Test") }
6
+ let(:config) { mock(Config, :ignored_tables => [], :connection => nil) }
7
+ let(:connection) do
8
+ mock(::ActiveRecord::ConnectionAdapters::AbstractAdapter, :tables => ["Test"], :columns => columns)
9
+ end
10
+ let(:columns) { [mock(Column)] }
11
+
12
+ before do
13
+ ::ActiveRecord::Base.stub(:connection).and_return(connection)
14
+ Table.stub(:new => table)
22
15
  end
23
16
 
24
17
  describe ".new" do
25
- it "creates a table with the table name, column definitions and conventions" do
26
- Table.should_receive(:new).with("Test", @columns, @conventions).and_return(@table)
27
- @database = Database.new(@conventions)
28
- @database.tables.first.should == @table
18
+ it "creates a table with the table name, column definitions and config" do
19
+ Table.should_receive(:new).with("Test", columns, config).and_return(table)
20
+ Database.new(config).tables.first.should == table
29
21
  end
30
22
 
31
- describe "has many relationships" do
23
+ context "has many relationships" do
32
24
 
33
- describe "conventional" do
25
+ context "conventional" do
34
26
  before(:each) do
35
- @connection.stub(:tables).and_return(["sites", "pages"])
27
+ connection.stub(:tables).and_return(["sites", "pages"])
36
28
 
37
29
  Table.unstub!(:new)
38
30
  @site_columns = [Column.new("name", nil, "string")]
39
31
  @pages_columns = [Column.new("site_id", nil, "integer")]
40
- @connection.stub(:columns).with("sites").and_return(@site_columns)
41
- @connection.stub(:columns).with("pages").and_return(@pages_columns)
42
- @database = Database.new(Conventions.new)
32
+ connection.stub(:columns).with("sites").and_return(@site_columns)
33
+ connection.stub(:columns).with("pages").and_return(@pages_columns)
34
+ @database = Database.new(Config.new)
43
35
  end
44
36
 
45
37
  it "sets the table name" do
@@ -52,15 +44,15 @@ module ConventionalModels
52
44
  end
53
45
  end
54
46
 
55
- describe "unconventional" do
47
+ context "unconventional" do
56
48
  before(:each) do
57
- @connection.stub(:tables).and_return(["Site", "Page"])
49
+ connection.stub(:tables).and_return(["Site", "Page"])
58
50
  Table.unstub!(:new)
59
51
  @site_columns = [Column.new("Name", nil, "string")]
60
52
  @pages_columns = [Column.new("Site_id", nil, "integer")]
61
- @connection.stub(:columns).with("Site").and_return(@site_columns)
62
- @connection.stub(:columns).with("Page").and_return(@pages_columns)
63
- @database = Database.new(Conventions.new{ primary_key_name "ID" })
53
+ connection.stub(:columns).with("Site").and_return(@site_columns)
54
+ connection.stub(:columns).with("Page").and_return(@pages_columns)
55
+ @database = Database.new(Config.new{ primary_key_name "ID" })
64
56
  end
65
57
 
66
58
  it "sets the table name" do
@@ -75,34 +67,34 @@ module ConventionalModels
75
67
  end
76
68
 
77
69
  it "ignores tables" do
78
- @conventions = Conventions.new do
70
+ config = Config.new do
79
71
  ignore_tables "Test"
80
72
  end
81
- @table.should_not_receive(:apply_conventions)
82
- @database = Database.new(@conventions)
73
+ table.should_not_receive(:apply_conventions)
74
+ @database = Database.new(config)
83
75
  end
84
76
  end
85
77
 
86
78
  describe "code outputting" do
87
79
  before(:each) do
88
- @table.stub(:name).and_return("Test")
80
+ table.stub(:name).and_return("Test")
89
81
  end
90
82
  describe "#code" do
91
83
  it "should return the code for each table" do
92
- @table.should_receive(:code).and_return("test")
93
- @database = Database.new(@conventions)
84
+ table.should_receive(:code).and_return("test")
85
+ @database = Database.new(config)
94
86
  @database.code.should == "test"
95
87
  end
96
88
  end
97
89
 
98
90
  describe "#code_for" do
99
91
  it "should return the model code for a specific table" do
100
- @table.should_receive(:code).and_return("test")
101
- @database = Database.new(@conventions)
92
+ table.should_receive(:code).and_return("test")
93
+ @database = Database.new(config)
102
94
  @database.code_for("Test").should == "test"
103
95
  end
104
96
  it "should return not found for unknown tables" do
105
- @database = Database.new(@conventions)
97
+ @database = Database.new(config)
106
98
  @database.code_for("SomeTable").should == "SomeTable not found"
107
99
  end
108
100
  end
@@ -7,7 +7,7 @@ module ConventionalModels
7
7
  @option_parser.options
8
8
  end
9
9
 
10
- describe "parsing" do
10
+ context "parsing" do
11
11
  it "accepts a database config file" do
12
12
  options_for(["-c", "config/db.yml"]).config.should == "config/db.yml"
13
13
  options_for(["--config", "config/db.yml"]).config.should == "config/db.yml"
@@ -34,7 +34,7 @@ module ConventionalModels
34
34
  end
35
35
  end
36
36
 
37
- describe "invalid arguments" do
37
+ context "invalid arguments" do
38
38
  it "should set parsed_options? to false" do
39
39
  options_for(["--boobs"])
40
40
  @option_parser.parsed_options?.should == false
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  module ConventionalModels
4
4
  describe Options do
5
- before(:each) do
5
+ before do
6
6
  @options = Options.new
7
7
  end
8
8
 
9
- describe "default options" do
9
+ context "default options" do
10
10
  it "should use rails location for default database.yml" do
11
11
  @options.config.should == "config/database.yml"
12
12
  end
@@ -2,10 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  module ConventionalModels
4
4
  describe Table do
5
- before(:each) do
6
- @columns = [mock(Column, :name => "test")]
7
- @conventions = Conventions.new
8
- end
5
+ let(:columns) { [mock(Column, :name => "test")] }
6
+ let(:config) { Config.new }
9
7
 
10
8
  def has_item?(array, expected)
11
9
  @found = false
@@ -17,69 +15,69 @@ module ConventionalModels
17
15
 
18
16
  describe ".new" do
19
17
  it "sets the name" do
20
- Table.new("test", @columns, @conventions).name.should == "test"
18
+ Table.new("test", columns, config).name.should == "test"
21
19
  end
22
20
 
23
21
  it "sets the columns" do
24
- Table.new("test", @columns, @conventions).columns.should == @columns
22
+ Table.new("test", columns, config).columns.should == columns
25
23
  end
26
24
  end
27
25
 
28
26
  describe "#==" do
29
27
  it "is true for tables with the same name" do
30
- Table.new("Page", @columns, @conventions).should == Table.new("Page", @columns, @conventions)
28
+ Table.new("Page", columns, config).should == Table.new("Page", columns, config)
31
29
  end
32
30
 
33
31
  it "is false for tables with different names" do
34
- Table.new("Page", @columns, @conventions).should_not == Table.new("Bar", @columns, @conventions)
32
+ Table.new("Page", columns, config).should_not == Table.new("Bar", columns, config)
35
33
  end
36
34
  end
37
35
 
38
36
  describe "#conventional_name?" do
39
37
  it "is true for tables that have a name that matches rails conventions" do
40
- Table.new("Page", @columns, @conventions).conventional_name?.should be_false
41
- Table.new("pages", @columns, @conventions).conventional_name?.should be_true
38
+ Table.new("Page", columns, config).conventional_name?.should be_false
39
+ Table.new("pages", columns, config).conventional_name?.should be_true
42
40
  end
43
41
  end
44
42
 
45
43
  describe ".new" do
46
44
  it "sets the primary key" do
47
- @conventions = Conventions.new do
45
+ config = Config.new do
48
46
  primary_key_name "ID"
49
47
  end
50
- @table = Table.new("Page", @columns, @conventions)
48
+ @table = Table.new("Page", columns, config)
51
49
  has_item?(@table.lines, "set_primary_key \"ID\"").should be_true
52
50
  end
53
51
 
54
52
  it "doesn't set the primary key when it is the rails default" do
55
- @table = Table.new("Page", @columns, @conventions)
53
+ @table = Table.new("Page", columns, config)
56
54
  has_item?(@table.lines, "set_primary_key \"id\"").should_not == be_true
57
55
  end
58
56
 
59
57
  it "sets the table name" do
60
- @table = Table.new("Page", @columns, @conventions)
58
+ @table = Table.new("Page", columns, config)
61
59
  has_item?(@table.lines, "set_table_name \"Page\"").should be_true
62
60
  end
63
61
 
64
62
  it "doesn't set the table name if it is the rails default" do
65
- @table = Table.new("pages", @columns, @conventions)
63
+ @table = Table.new("pages", columns, config)
66
64
  has_item?(@table.lines, "set_table_name \"pages\"").should be_false
67
65
  end
68
66
 
69
67
  it "sets the class name" do
70
- @conventions = Conventions.new do
68
+ config = Config.new do
71
69
  class_name do |table|
72
70
  "BOO"
73
71
  end
74
72
  end
75
- @table = Table.new("Page", @columns, @conventions)
73
+ @table = Table.new("Page", columns, config)
76
74
  @table.class_name.should == "BOO"
77
75
  end
78
76
 
79
77
  it "sets belongs to columns" do
80
- @conventions = Conventions.new
81
- @columns = [Column.new("Site_id", nil, "integer")]
82
- @table = Table.new("Page", @columns, @conventions)
78
+ config = Config.new
79
+ columns = [Column.new("Site_id", nil, "integer")]
80
+ @table = Table.new("Page", columns, config)
83
81
  has_item?(@table.lines, "belongs_to :site, :class_name => 'Site'").should be_true
84
82
  @table.belongs_to_names.first.name.should == "Site_id"
85
83
  end
@@ -88,7 +86,7 @@ module ConventionalModels
88
86
 
89
87
  describe "#code" do
90
88
  before(:each) do
91
- @table = Table.new("pages", @columns, @conventions)
89
+ @table = Table.new("pages", columns, config)
92
90
  end
93
91
 
94
92
  it "returns an activerecord class" do
@@ -2,36 +2,25 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  module ConventionalModels
4
4
  describe ConventionalModels do
5
- before(:each) do
6
- @conventions = mock(Conventions)
7
- Conventions.stub(:new => @conventions)
8
-
5
+ let(:config) { mock(Config) }
6
+ let(:generated_code) { mock(String) }
7
+ let(:database) { mock(Database, :code => generated_code, :apply_conventions => nil) }
8
+
9
+ before do
10
+ Config.stub(:new => config)
11
+ Database.stub(:new => database)
9
12
  ConventionalModels.stub(:run_code)
10
-
11
- @generated_code = mock(String)
12
- @database = mock(Database, :code => @generated_code)
13
- @database.stub(:apply_conventions).with(@conventions)
14
- Database.stub(:new => @database)
15
-
16
- ConventionalModels.stub(:remove)
17
13
  end
18
14
 
19
15
  describe ".configure" do
20
- describe "with no args" do
16
+ context "with no args" do
21
17
  it "creates a database object with the conventions" do
22
- Database.should_receive(:new).with(@conventions).and_return(@database)
18
+ Database.should_receive(:new).with(config).and_return(database)
23
19
  ConventionalModels.configure
24
20
  end
25
21
 
26
22
  it "run the generated code" do
27
- ConventionalModels.should_receive(:run_code).with(@generated_code)
28
- ConventionalModels.configure
29
- end
30
- end
31
- describe "second call" do
32
- it "should call remove if a database has already been configured" do
33
- ConventionalModels.should_receive(:remove).with(@database)
34
- ConventionalModels.configure
23
+ ConventionalModels.should_receive(:run_code).with(generated_code)
35
24
  ConventionalModels.configure
36
25
  end
37
26
  end
@@ -48,13 +37,13 @@ module ConventionalModels
48
37
  describe ".model_code" do
49
38
  it "returns the database code" do
50
39
  ConventionalModels.configure
51
- ConventionalModels.model_code.should == @generated_code
40
+ ConventionalModels.model_code.should == generated_code
52
41
  end
53
42
  end
54
43
 
55
44
  describe ".model_code_for" do
56
45
  it "returns the model code for a specific model" do
57
- @database.should_receive(:code_for).with("Test").and_return("test")
46
+ database.should_receive(:code_for).with("Test").and_return("test")
58
47
  ConventionalModels.configure
59
48
  ConventionalModels.model_code_for("Test").should == "test"
60
49
  end
@@ -68,18 +57,5 @@ module ConventionalModels
68
57
  ConventionalModels.run_console!
69
58
  end
70
59
  end
71
-
72
- describe ".remove" do
73
- before(:each) do
74
- ConventionalModels.unstub(:remove)
75
- table = mock(Table, :class_name => "TestTable")
76
- @database.should_receive(:tables).and_return([table])
77
- Object.should_receive(:send).with(:remove_const, :TestTable)
78
- end
79
-
80
- it "removes the table constants from the environment" do
81
- ConventionalModels.remove(@database)
82
- end
83
- end
84
60
  end
85
61
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Steve Hodgkiss
@@ -14,13 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-11 00:00:00 +01:00
17
+ date: 2010-05-09 00:00:00 +01:00
18
18
  default_executable: cmconsole
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
22
- type: :development
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
@@ -29,12 +29,12 @@ dependencies:
29
29
  - 3
30
30
  - 0
31
31
  version: 1.3.0
32
- prerelease: false
33
- requirement: *id001
32
+ type: :development
33
+ version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: cucumber
36
- type: :development
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
@@ -43,12 +43,12 @@ dependencies:
43
43
  - 6
44
44
  - 4
45
45
  version: 0.6.4
46
- prerelease: false
47
- requirement: *id002
46
+ type: :development
47
+ version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: aruba
50
- type: :development
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
@@ -57,12 +57,12 @@ dependencies:
57
57
  - 1
58
58
  - 7
59
59
  version: 0.1.7
60
- prerelease: false
61
- requirement: *id003
60
+ type: :development
61
+ version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: activerecord
64
- type: :runtime
65
- version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
@@ -71,8 +71,8 @@ dependencies:
71
71
  - 3
72
72
  - 5
73
73
  version: 2.3.5
74
- prerelease: false
75
- requirement: *id004
74
+ type: :runtime
75
+ version_requirements: *id004
76
76
  description: Generate ActiveRecord models automatically with basic relationships based on conventions.
77
77
  email: steve@hodgkiss.me.uk
78
78
  executables:
@@ -83,49 +83,26 @@ extra_rdoc_files:
83
83
  - LICENSE
84
84
  - README.rdoc
85
85
  files:
86
- - .document
87
- - .gitignore
88
- - Gemfile
89
- - Gemfile.lock
90
- - LICENSE
91
- - README.rdoc
92
- - Rakefile
93
- - VERSION
94
- - bin/cmconsole
95
- - conventional_models.gemspec
96
- - features/cmconsole.feature
97
- - features/conventional_models.feature
98
- - features/output_model_code.feature
99
- - features/step_definitions/cmconsole_steps.rb
100
- - features/step_definitions/conventional_models_steps.rb
101
- - features/step_definitions/output_model_code_steps.rb
102
- - features/support/env.rb
103
- - lib/conventional_models.rb
104
86
  - lib/conventional_models/active_record_base_model_for.rb
105
87
  - lib/conventional_models/cli.rb
106
88
  - lib/conventional_models/column.rb
107
- - lib/conventional_models/conventions.rb
89
+ - lib/conventional_models/config.rb
108
90
  - lib/conventional_models/database.rb
109
91
  - lib/conventional_models/option_parser.rb
110
92
  - lib/conventional_models/options.rb
111
93
  - lib/conventional_models/table.rb
112
94
  - lib/conventional_models/version.rb
113
- - spec/conventional_models/cli_spec.rb
114
- - spec/conventional_models/conventions_spec.rb
115
- - spec/conventional_models/database_spec.rb
116
- - spec/conventional_models/option_parser_spec.rb
117
- - spec/conventional_models/options_spec.rb
118
- - spec/conventional_models/table_spec.rb
119
- - spec/conventional_models_spec.rb
120
- - spec/spec.opts
121
- - spec/spec_helper.rb
95
+ - lib/conventional_models.rb
96
+ - bin/cmconsole
97
+ - LICENSE
98
+ - README.rdoc
122
99
  has_rdoc: true
123
100
  homepage: http://github.com/stevehodgkiss/conventional_models
124
101
  licenses: []
125
102
 
126
103
  post_install_message:
127
- rdoc_options:
128
- - --charset=UTF-8
104
+ rdoc_options: []
105
+
129
106
  require_paths:
130
107
  - lib
131
108
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -140,21 +117,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
117
  - - ">="
141
118
  - !ruby/object:Gem::Version
142
119
  segments:
143
- - 0
144
- version: "0"
120
+ - 1
121
+ - 3
122
+ - 6
123
+ version: 1.3.6
145
124
  requirements: []
146
125
 
147
- rubyforge_project:
126
+ rubyforge_project: conventional_models
148
127
  rubygems_version: 1.3.6
149
128
  signing_key:
150
129
  specification_version: 3
151
130
  summary: Generate ActiveRecord models. For lazy people.
152
131
  test_files:
153
132
  - spec/conventional_models/cli_spec.rb
154
- - spec/conventional_models/conventions_spec.rb
133
+ - spec/conventional_models/config_spec.rb
155
134
  - spec/conventional_models/database_spec.rb
156
135
  - spec/conventional_models/option_parser_spec.rb
157
136
  - spec/conventional_models/options_spec.rb
158
137
  - spec/conventional_models/table_spec.rb
159
138
  - spec/conventional_models_spec.rb
160
139
  - spec/spec_helper.rb
140
+ - features/cmconsole.feature
141
+ - features/conventional_models.feature
142
+ - features/multiple_databases.feature
143
+ - features/output_model_code.feature
144
+ - features/step_definitions/cmconsole_steps.rb
145
+ - features/step_definitions/conventional_models_steps.rb
146
+ - features/step_definitions/multiple_databases.rb
147
+ - features/step_definitions/output_model_code_steps.rb
148
+ - features/support/env.rb
149
+ - Gemfile
150
+ - Gemfile.lock