public
Clone URL: git://github.com/edspencer/ext-rails-app-generator.git
Updated model specs with new validation expectations
edspencer (author)
Mon Aug 25 08:22:58 -0700 2008
commit  a3da0b1d2c5e43a35634b98e73923413b421a82e
tree    ad0f607c35f3c25da90fbc90f6d2cbfbddaa1acc
parent  e5d59fd9e4e30873e028a1894805b4fe08668b12
...
16
17
18
19
20
21
22
23
24
...
46
47
48
 
 
 
...
16
17
18
 
 
 
19
20
21
...
43
44
45
46
47
48
0
@@ -16,9 +16,6 @@
0
 [submodule "vendor/plugins/rspec_rails"]
0
   path = vendor/plugins/rspec_rails
0
   url = git://github.com/dchelimsky/rspec-rails.git
0
-[submodule "vendor/plugins/rspec_on_rails_matchers"]
0
- path = vendor/plugins/rspec_on_rails_matchers
0
- url = git://github.com/joshknowles/rspec-on-rails-matchers.git
0
 [submodule "vendor/plugins/ext_mvc_rails"]
0
   path = vendor/plugins/ext_mvc_rails
0
   url = git://github.com/edspencer/ext-mvc-rails.git
0
@@ -46,3 +43,6 @@
0
 [submodule "vendor/plugins/acts_as_state_machine"]
0
   path = vendor/plugins/acts_as_state_machine
0
   url = git://github.com/omghax/acts_as_state_machine.git
0
+[submodule "vendor/plugins/rspec_validation_expectations"]
0
+ path = vendor/plugins/rspec_validation_expectations
0
+ url = git://github.com/edspencer/rspec_validation_expectations.git
...
4
5
6
7
 
8
9
...
4
5
6
 
7
8
9
0
@@ -4,6 +4,6 @@ class Association < ActiveRecord::Base
0
   belongs_to :model
0
   belongs_to :foreign_model, :class_name => 'Model'
0
   
0
- validates_presence_of :association_type
0
+ validates_presence_of :association_type, :model_id, :foreign_model_id
0
   validates_inclusion_of :association_type, :in => ASSOCIATION_TYPES
0
 end
...
6
7
8
9
10
...
6
7
8
 
9
0
@@ -6,5 +6,4 @@ class Model < ActiveRecord::Base
0
   has_many :controllers
0
   
0
   validates_presence_of :site_id, :name
0
-
0
 end
...
46
47
48
49
50
51
52
53
 
 
 
 
 
 
 
54
...
46
47
48
 
 
 
 
49
50
51
52
53
54
55
56
57
0
@@ -46,7 +46,10 @@
0
           %td= controller.responds_to_xml ? 'Yes' : 'No'
0
           %td= controller.responds_to_json ? 'Yes' : 'No'
0
 
0
-
0
-- form_tag(generate_site_path(@site), :class => 'generate_site') do
0
- .submitRow
0
- = submit_tag "Generate"
0
\ No newline at end of file
0
+%h2 Options
0
+- if @site.new? || @site.generated?
0
+ - form_tag(generate_site_path(@site), :class => 'generate_site') do
0
+ .submitRow
0
+ = submit_tag "Generate"
0
+- else
0
+ %p= "You can't generate this site right now because it is already #{@site.state.humanize}"
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
25
26
27
28
 
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
68
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
 
 
 
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
0
@@ -1,68 +1,10 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe Association do
0
- before(:each) do
0
- @valid_attributes = {
0
- :model_id => "1",
0
- :foreign_model_id => "1",
0
- :association_type => "has_many"
0
- }
0
-
0
- @association = Association.new
0
- end
0
-
0
- it "should create a new instance given valid attributes" do
0
- Association.create!(@valid_attributes)
0
- end
0
-
0
- it "should belong to model" do
0
- @association.should belong_to(:model)
0
- end
0
-
0
- it "should belong to foreign_model" do
0
- @association.should belong_to(:foreign_model)
0
- end
0
+ it_should_be_createable :with => {:model_id => 1, :foreign_model_id => 1, :association_type => 'has_many'}
0
   
0
- it "should validate presence of association_type" do
0
- @association.should validate_presence_of(:association_type)
0
- end
0
+ it_should_validate_presence_of :model_id, :foreign_model_id, :association_type
0
+ it_should_validate_inclusion_of :association_type, :in => %w(has_many has_one belongs_to has_and_belongs_to_many)
0
   
0
- describe "the association_type" do
0
- before(:each) do
0
- @association = Association.new(:model_id => "1", :foreign_model_id => "2")
0
- end
0
-
0
- #TODO: Write a custom matcher for these
0
- it "may be has_many" do
0
- @association.should_not be_valid
0
- @association.association_type = "has_many"
0
- @association.should be_valid
0
- end
0
-
0
- it "may be has_one" do
0
- @association.should_not be_valid
0
- @association.association_type = "has_one"
0
- @association.should be_valid
0
- end
0
-
0
- it "may be belongs_to" do
0
- @association.should_not be_valid
0
- @association.association_type = "belongs_to"
0
- @association.should be_valid
0
- end
0
-
0
- it "may be has_and_belongs_to_many" do
0
- @association.should_not be_valid
0
- @association.association_type = "has_and_belongs_to_many"
0
- @association.should be_valid
0
- end
0
-
0
- it "should not be any other value" do
0
- #FIXME: There must be a better way to do all this
0
- %w(some other values which are not allowed).each do |bad_value|
0
- @association.association_type = bad_value
0
- @association.should_not be_valid
0
- end
0
- end
0
- end
0
+ it_should_belong_to :model, :foreign_model
0
 end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
36
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
0
@@ -1,36 +1,7 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe Column do
0
- before(:each) do
0
- @valid_attributes = {
0
- :model_id => "1",
0
- :name => "value for name",
0
- :column_type => "value for column_type",
0
- :default_value => "value for default_value",
0
- :appears_in_views => false,
0
- :column_type => 'string'
0
- }
0
-
0
- @column = Column.new
0
- end
0
-
0
- it "should create a new instance given valid attributes" do
0
- Column.create!(@valid_attributes)
0
- end
0
-
0
- it "should belong to a model" do
0
- @column.should belong_to(:model)
0
- end
0
-
0
- it "should validate presence of model_id" do
0
- @column.should validate_presence_of(:model_id)
0
- end
0
-
0
- it "should validate presence of name" do
0
- @column.should validate_presence_of(:name)
0
- end
0
-
0
- it "should validate presence of column_type" do
0
- @column.should validate_presence_of(:column_type)
0
- end
0
+ it_should_be_createable :with => {:model_id => 1, :name => 'test', :column_type => 'string'}
0
+ it_should_validate_presence_of :model_id, :name, :column_type
0
+ it_should_belong_to :model
0
 end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
 
 
31
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
0
@@ -1,31 +1,7 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe Controller do
0
- before(:each) do
0
- @valid_attributes = {
0
- :model_id => "1",
0
- :name => "value for name",
0
- :lft => "1",
0
- :rgt => "1",
0
- :parent_id => "1",
0
- :namespace => "value for namespace",
0
- :responds_to_html => false,
0
- :responds_to_xml => false,
0
- :responds_to_json => false
0
- }
0
-
0
- @controller = Controller.new
0
- end
0
-
0
- it "should create a new instance given valid attributes" do
0
- Controller.create!(@valid_attributes)
0
- end
0
-
0
- it "should belong to model" do
0
- @controller.should belong_to(:model)
0
- end
0
-
0
- it "should validate presence of name" do
0
- @controller.should validate_presence_of(:name)
0
- end
0
+ it_should_be_createable :with => {:name => 'test'}
0
+ it_should_validate_presence_of :name
0
+ it_should_belong_to :model
0
 end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
 
 
24
25
26
27
 
28
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
6
 
 
 
7
8
0
@@ -1,28 +1,8 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
-describe Log do
0
- before(:each) do
0
- @valid_attributes = {
0
- :site_id => "1",
0
- :message => "value for message"
0
- }
0
-
0
- @log = Log.new
0
- end
0
-
0
- it "should create a new instance given valid attributes" do
0
- Log.create!(@valid_attributes)
0
- end
0
-
0
- it "should belong to site" do
0
- @log.should belong_to(:site)
0
- end
0
-
0
- it "should validate presence of site_id" do
0
- @log.should validate_presence_of(:site_id)
0
- end
0
+describe Log do
0
+ it_should_validate_presence_of :site_id, :message
0
+ it_should_be_createable :with => {:site_id => "1",:message => "value for message"}
0
   
0
- it "should validate presence of message" do
0
- @log.should validate_presence_of(:message)
0
- end
0
+ it_should_belong_to(:site)
0
 end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
39
40
41
42
 
 
43
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
 
 
 
7
8
9
0
@@ -1,43 +1,9 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe Model do
0
- before(:each) do
0
- @valid_attributes = {
0
- :name => "value for name",
0
- :site_id => "1"
0
- }
0
- @model = Model.new
0
- end
0
-
0
- it "should create a new instance given valid attributes" do
0
- Model.create!(@valid_attributes)
0
- end
0
-
0
- it "should have many columns" do
0
- @model.should have_many(:columns)
0
- end
0
-
0
- it "should have many validations" do
0
- @model.should have_many(:validations)
0
- end
0
-
0
- it "should have many associations" do
0
- @model.should have_many(:associations)
0
- end
0
-
0
- it "should have many controllers" do
0
- @model.should have_many(:controllers)
0
- end
0
-
0
- it "should validate presence of site_id" do
0
- @model.should validate_presence_of(:site_id)
0
- end
0
-
0
- it "should validate presence of name" do
0
- @model.should validate_presence_of(:name)
0
- end
0
+ it_should_validate_presence_of :site_id, :name
0
+ it_should_be_createable :with => {:name => 'some name', :site_id => "1"}
0
   
0
- it "should belong to a site" do
0
- @model.should belong_to(:site)
0
- end
0
+ it_should_have_many :columns, :validations, :associations, :controllers
0
+ it_should_belong_to :site
0
 end
...
1
2
3
 
 
 
4
 
 
 
 
5
6
7
...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
0
@@ -1,7 +1,14 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe Plugin do
0
+ it_should_be_createable :with => {:name => 'test', :remote_url => 'test', :local_path => 'test'}
0
+ it_should_validate_presence_of :remote_url, :local_path, :name
0
+ it_should_validate_uniqueness_of :remote_url, :local_path, :name
0
   
0
+ it "should not be selected by default unless specified" do
0
+ Plugin.new.selected_by_default.should == false
0
+ end
0
+
0
   describe "when deciding whether a generate call is required" do
0
     before(:each) do
0
       @plugin = Plugin.new
0
@@ -23,50 +30,5 @@ describe Plugin do
0
       end
0
     end
0
   end
0
-
0
- describe "validations" do
0
- before(:each) do
0
- @valid_attributes = {
0
- :name => "name",
0
- :remote_url => "value for remote_url",
0
- :local_path => "value for local_path",
0
- :generator_name => "value for generator_name",
0
- :default_generator_argument => "value for default_generator_argument"
0
- }
0
-
0
- @plugin = Plugin.new
0
- end
0
 
0
- it "should create a new instance given valid attributes" do
0
- Plugin.create!(@valid_attributes)
0
- end
0
-
0
- it "should validate presence of remote_url" do
0
- @plugin.should validate_presence_of(:remote_url)
0
- end
0
-
0
- it "should validate presence of local_path" do
0
- @plugin.should validate_presence_of(:local_path)
0
- end
0
-
0
- it "should validate presence of name" do
0
- @plugin.should validate_presence_of(:name)
0
- end
0
-
0
- it "should not be selected by default unless specified" do
0
- @plugin.selected_by_default.should == false
0
- end
0
-
0
- it "should validate uniqueness of remote_url" do
0
- @plugin.should validate_uniqueness_of(:remote_url)
0
- end
0
-
0
- it "should validate uniqueness of local_path" do
0
- @plugin.should validate_uniqueness_of(:local_path)
0
- end
0
-
0
- it "should validate uniqueness of name" do
0
- @plugin.should validate_uniqueness_of(:name)
0
- end
0
- end
0
 end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
...
1
2
3
 
 
 
 
 
 
 
 
 
 
4
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
0
@@ -1,38 +1,10 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe SelectedPlugin do
0
- describe "validations" do
0
- before(:each) do
0
- @valid_attributes = {
0
- :site_id => "1",
0
- :plugin_id => "1",
0
- :generator_argument => "value for generator_argument"
0
- }
0
-
0
- @selected_plugin = SelectedPlugin.new
0
- end
0
+ it_should_be_createable :with => {:site_id => 1, :plugin_id => 1}
0
+ it_should_validate_presence_of :site_id, :plugin_id
0
+ it_should_belong_to :site, :plugin
0
 
0
- it "should create a new instance given valid attributes" do
0
- SelectedPlugin.create!(@valid_attributes)
0
- end
0
-
0
- it "should belong to site" do
0
- @selected_plugin.should belong_to(:site)
0
- end
0
-
0
- it "should belong to plugin" do
0
- @selected_plugin.should belong_to(:plugin)
0
- end
0
-
0
- it "should validate presence of site_id" do
0
- @selected_plugin.should validate_presence_of(:site_id)
0
- end
0
-
0
- it "should validate presence of plugin_id" do
0
- @selected_plugin.should validate_presence_of(:plugin_id)
0
- end
0
- end
0
-
0
   describe "the generator argument" do
0
     before(:each) do
0
       @plugin = mock_model(Plugin, :default_generator_argument => "default arg", :generator_name => "some_generator")
...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
 
 
 
31
32
33
...
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
11
12
13
14
0
@@ -5,29 +5,10 @@ describe Site do
0
     @site = Site.new(:generation_start_time => 5.minutes.ago, :generation_stop_time => 2.minutes.ago)
0
   end
0
   
0
- it "should validate presence of user_id" do
0
- @site.should validate_presence_of(:user_id)
0
- end
0
-
0
- it "should validate presence of name" do
0
- @site.should validate_presence_of(:name)
0
- end
0
-
0
- it "should belong to a user" do
0
- @site.should belong_to(:user)
0
- end
0
-
0
- it "should have many models" do
0
- @site.should have_many(:models)
0
- end
0
-
0
- it "should have many controllers" do
0
- @site.should have_many(:controllers)
0
- end
0
-
0
- it "should have many logs" do
0
- @site.should have_many(:logs)
0
- end
0
+ it_should_be_createable :with => {:user_id => 1, :name => 'test'}
0
+ it_should_validate_presence_of :user_id, :name
0
+ it_should_belong_to :user
0
+ it_should_have_many :models, :controllers, :logs
0
   
0
   it "should return the correct generate time" do
0
     @site.generation_time.should == 3.minutes
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
 
 
24
25
26
...
1
2
3
 
 
 
 
 
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
5
6
7
8
9
10
0
@@ -1,26 +1,10 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
 
0
 describe Validation do
0
- before(:each) do
0
- @valid_attributes = {
0
- :column_id => "1",
0
- :validation_type => "validates_presence_of"
0
- }
0
-
0
- @validation = Validation.new
0
- end
0
 
0
- it "should create a new instance given valid attributes" do
0
- Validation.create!(@valid_attributes)
0
- end
0
-
0
- it "should belong to column" do
0
- @validation.should belong_to(:column)
0
- end
0
-
0
- it "should validate presence of column_id" do
0
- @validation.should validate_presence_of(:column_id)
0
- end
0
+ it_should_be_createable :with => {:column_id => "1", :validation_type => "validates_presence_of"}
0
+ it_should_belong_to :column
0
+ it_should_validate_presence_of :column_id
0
   
0
   describe "the validation_type" do
0
     before(:each) do
...
7
8
9
10
11
12
13
14
...
7
8
9
 
 
 
10
11
0
@@ -7,8 +7,5 @@ describe "/sites/show.html.erb" do
0
     assigns[:site] = @site = stub_model(Site)
0
   end
0
 
0
- it "should render attributes in <p>" do
0
- render "/sites/show.html.erb"
0
- end
0
 end
0
 

Comments

    No one has commented yet.