rails3_artifactor 0.1.5 → 0.2.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.1
@@ -45,9 +45,13 @@ module Rails3::Assist::Artifact
45
45
  alias_method :#{name}_file?, :has_#{name}?
46
46
 
47
47
  def #{name}_file name, &block
48
- found = existing_file_name(name, :#{name}).path
49
- yield found if block && found
50
- found
48
+ begin
49
+ found = existing_file_name(name, :#{name}).path
50
+ yield found if block && found
51
+ found
52
+ rescue
53
+ nil
54
+ end
51
55
  end
52
56
 
53
57
  def create_#{name} name, options={}, &block
@@ -55,11 +59,20 @@ module Rails3::Assist::Artifact
55
59
  end
56
60
 
57
61
  def insert_into_#{name}(name, options={}, &block)
58
- insert_into_artifact(name, set(options, :#{name}), &block)
62
+ begin
63
+ insert_into_artifact(name, set(options, :#{name}), &block)
64
+ true
65
+ rescue
66
+ nil
67
+ end
59
68
  end
60
69
 
61
70
  def read_#{name}(name, options={}, &block)
62
- read_artifact(name, set(options, :#{name}), &block)
71
+ begin
72
+ read_artifact(name, set(options, :#{name}), &block)
73
+ rescue
74
+ nil
75
+ end
63
76
  end
64
77
 
65
78
  def remove_#{name} name
@@ -71,14 +84,17 @@ module Rails3::Assist::Artifact
71
84
  end
72
85
 
73
86
  def remove_all_#{plural_name}
74
- Rails3::Assist::Artifact::Files.#{name}_files.each{|f| ::File.delete_file! f}
87
+ Rails3::Assist::Artifact::Files.#{name}_files.each do |file_name|
88
+ ::File.delete_file! file_name if ::File.file?(file_name)
89
+ end
75
90
  end
76
91
  alias_method :delete_all_#{plural_name}, :remove_all_#{plural_name}
77
92
 
78
93
  def remove_#{plural_name} *names
79
94
  return remove_all_#{plural_name} if names.empty?
80
95
  names.to_strings.each do |name|
81
- ::File.delete #{name}_file(name)
96
+ file_name = #{name}_file(name)
97
+ ::File.delete!(file_name) if file_name && ::File.file?(file_name)
82
98
  end
83
99
  end
84
100
  alias_method :delete_#{plural_name}, :remove_#{plural_name}
@@ -19,7 +19,7 @@ module Rails3::Assist::Artifact
19
19
  end
20
20
  return result
21
21
  elsif type == :migration
22
- raise "The method #find_#{type} to find the migration is not available!"
22
+ raise StandardError, "The method #find_#{type} to find the migration is not available!"
23
23
  end
24
24
 
25
25
  # default for non-migration
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails3_artifactor}
8
- s.version = "0.1.5"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-09-15}
12
+ s.date = %q{2010-09-16}
13
13
  s.description = %q{Helpers for handling Rails 3 artifacts in general, such as CRUD operations etc.}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -51,14 +51,7 @@ Gem::Specification.new do |s|
51
51
  "lib/rails3_artifactor/rspec/macro.rb",
52
52
  "rails3_artifactor.gemspec",
53
53
  "spec/fixtures.rb",
54
- "spec/fixtures/app/controllers/account_controller.rb",
55
- "spec/fixtures/app/helpers/account_helper.rb",
56
- "spec/fixtures/app/mailers/account_mailer.rb",
57
- "spec/fixtures/app/models/account.rb",
58
- "spec/fixtures/app/models/account_observer.rb",
59
54
  "spec/fixtures/app/views/account/edit.html.erb",
60
- "spec/fixtures/app/views/account/show.html.erb",
61
- "spec/fixtures/db/migrations/20100913162614_create_account.rb",
62
55
  "spec/rails3_artifactor/artifact/base_spec.rb",
63
56
  "spec/rails3_artifactor/artifact/crud/controller_spec.rb",
64
57
  "spec/rails3_artifactor/artifact/crud/helper_spec.rb",
@@ -91,13 +84,7 @@ Gem::Specification.new do |s|
91
84
  s.rubygems_version = %q{1.3.7}
92
85
  s.summary = %q{Helpers for handling Rails 3 artifacts}
93
86
  s.test_files = [
94
- "spec/fixtures/app/controllers/account_controller.rb",
95
- "spec/fixtures/app/helpers/account_helper.rb",
96
- "spec/fixtures/app/mailers/account_mailer.rb",
97
- "spec/fixtures/app/models/account.rb",
98
- "spec/fixtures/app/models/account_observer.rb",
99
- "spec/fixtures/db/migrations/20100913162614_create_account.rb",
100
- "spec/fixtures.rb",
87
+ "spec/fixtures.rb",
101
88
  "spec/rails3_artifactor/artifact/base_spec.rb",
102
89
  "spec/rails3_artifactor/artifact/crud/controller_spec.rb",
103
90
  "spec/rails3_artifactor/artifact/crud/helper_spec.rb",
@@ -1,5 +1,3 @@
1
1
 
2
- # hello
3
- # goodbye
4
- <h1><%= title %></h1>
2
+ <h1><%= title %></h1>
5
3
 
@@ -6,17 +6,47 @@ describe 'controller' do
6
6
  before :each do
7
7
  Rails3::Assist::Directory.rails_root = fixtures_dir
8
8
 
9
- remove_controller :account if has_controller? :account
9
+ remove_controller :account # if has_controller? :account
10
10
  create_controller :account do
11
11
  %q{
12
12
  def index
13
13
  end
14
14
  }
15
- end
15
+ end
16
+ end
17
+
18
+ after :each do
19
+ remove_controller :account
16
20
  end
17
21
 
18
- after :each do
19
- # remove_controller :account
22
+ context "Non-existant controller(s)" do
23
+ it "should not fail trying to remove non-existant controllers" do
24
+ remove_controllers :person, :user
25
+ remove_artifacts :controller, :person, :user
26
+
27
+ remove_controller :person
28
+ remove_artifact :controller, :person
29
+
30
+ end
31
+
32
+ it "should not find a non-existant controller" do
33
+ controller_file :person do |person|
34
+ fail "should not find person controller!"
35
+ end
36
+
37
+ has_controller?(:person).should be_false
38
+ has_controllers?(:person, :user).should be_false
39
+ end
40
+
41
+ it "should not insert into non-existant controller" do
42
+ insert_into_controller(:person, :after => 'Hello', :content => 'Yes').should_not be_true
43
+ end
44
+
45
+ it "should not read from non-existant controller" do
46
+ read_controller :person do |content|
47
+ fail "should not find person content!"
48
+ end.should_not be_true
49
+ end
20
50
  end
21
51
 
22
52
  it "should have an account_controller file that contains an index method and two inserted comments" do
@@ -6,7 +6,7 @@ describe 'helper' do
6
6
  before :each do
7
7
  Rails3::Assist::Directory.rails_root = fixtures_dir
8
8
 
9
- # remove_helper :account if has_helper? :account
9
+ remove_helper :account
10
10
  create_helper :account do
11
11
  %q{
12
12
  def index
@@ -16,15 +16,44 @@ describe 'helper' do
16
16
  end
17
17
 
18
18
  after :each do
19
- # remove_helper :account
19
+ remove_helper :account
20
+ end
21
+
22
+ context "Non-existant helper(s)" do
23
+ it "should not fail trying to remove non-existant helpers" do
24
+ remove_helpers :person, :user
25
+ remove_artifacts :helper, :person, :user
26
+
27
+ remove_helper :person
28
+ remove_artifact :helper, :person
29
+ end
30
+
31
+ it "should not find a non-existant helper" do
32
+ helper_file :person do |person|
33
+ fail "should not find person helper!"
34
+ end
35
+
36
+ has_helper?(:person).should be_false
37
+ has_helpers?(:person, :user).should be_false
38
+ end
39
+
40
+ it "should not insert into non-existant helper" do
41
+ insert_into_helper(:person, :after => 'Hello', :content => 'Yes').should_not be_true
42
+ end
43
+
44
+ it "should not read from non-existant helper" do
45
+ read_helper :person do |content|
46
+ fail "should not find person content!"
47
+ end.should_not be_true
48
+ end
20
49
  end
21
50
 
22
51
  it "should have an account_helper file that contains an index method and two inserted comments" do
23
- # insert_into_helper :account, :content => '# hello'
24
- # insert_into_helper :account do
25
- # '# goodbye'
26
- # end
27
- # read_helper(:account).should have_comment 'hello'
52
+ insert_into_helper :account, :content => '# hello'
53
+ insert_into_helper :account do
54
+ '# goodbye'
55
+ end
56
+ read_helper(:account).should have_comment 'hello'
28
57
  # puts read_helper(:account)
29
58
  # root_dir.should have_helper :account do |helper_file|
30
59
  # helper_file.should have_method :index
@@ -6,7 +6,7 @@ describe 'mailer' do
6
6
  before :each do
7
7
  Rails3::Assist::Directory.rails_root = fixtures_dir
8
8
 
9
- # remove_helper :account if has_helper? :account
9
+ remove_mailer :account if has_mailer? :account
10
10
  create_mailer :account do
11
11
  %q{ def mail_it
12
12
  end}
@@ -14,7 +14,36 @@ describe 'mailer' do
14
14
  end
15
15
 
16
16
  after :each do
17
- # remove_helper :account
17
+ remove_mailer :account
18
+ end
19
+
20
+ context "Non-existant mailer(s)" do
21
+ it "should not fail trying to remove non-existant mailers" do
22
+ remove_mailers :person, :user
23
+ remove_artifacts :mailer, :person, :user
24
+
25
+ remove_mailer :person
26
+ remove_artifact :mailer, :person
27
+ end
28
+
29
+ it "should not find a non-existant mailer" do
30
+ mailer_file :person do |person|
31
+ fail "should not find person mailer!"
32
+ end
33
+
34
+ has_mailer?(:person).should be_false
35
+ has_mailers?(:person, :user).should be_false
36
+ end
37
+
38
+ it "should not insert into non-existant mailer" do
39
+ insert_into_mailer(:person, :after => 'Hello', :content => 'Yes').should_not be_true
40
+ end
41
+
42
+ it "should not read from non-existant mailer" do
43
+ read_mailer :person do |content|
44
+ fail "should not find person content!"
45
+ end.should_not be_true
46
+ end
18
47
  end
19
48
 
20
49
  it "should have an account_mailer file that contains a #mail_it method and two inserted comments" do
@@ -24,10 +53,10 @@ describe 'mailer' do
24
53
  end
25
54
  read_mailer(:account).should have_comment 'hello'
26
55
  puts read_mailer(:account)
27
- # root_dir.should have_mailer :account do |helper_file|
28
- # helper_file.should have_method :index
29
- # helper_file.should have_comment 'hello'
30
- # helper_file.should have_comment 'goodbye'
56
+ # root_dir.should have_mailer :account do |mailer_file|
57
+ # mailer_file.should have_method :index
58
+ # mailer_file.should have_comment 'hello'
59
+ # mailer_file.should have_comment 'goodbye'
31
60
  # end
32
61
  end
33
62
  end
@@ -23,7 +23,36 @@ describe 'migration' do
23
23
  end
24
24
 
25
25
  after :each do
26
- # remove_migration :create_account
26
+ remove_migration :create_account
27
+ end
28
+
29
+ context "Non-existant migration(s)" do
30
+ it "should not fail trying to remove non-existant migrations" do
31
+ remove_migrations :person, :user
32
+ remove_artifacts :migration, :person, :user
33
+
34
+ remove_migration :person
35
+ remove_artifact :migration, :person
36
+ end
37
+
38
+ it "should not find a non-existant migration" do
39
+ migration_file :person do |person|
40
+ fail "should not find person migration!"
41
+ end
42
+
43
+ has_migration?(:person).should be_false
44
+ has_migrations?(:person, :user).should be_false
45
+ end
46
+
47
+ it "should not insert into non-existant migration" do
48
+ insert_into_migration(:person, :after => 'Hello', :content => 'Yes').should_not be_true
49
+ end
50
+
51
+ it "should not read from non-existant migration" do
52
+ read_migration :person do |content|
53
+ fail "should not find person content!"
54
+ end.should_not be_true
55
+ end
27
56
  end
28
57
 
29
58
  it "should have an create_account_migration file that contains an index method and two inserted comments" do
@@ -6,7 +6,7 @@ describe 'model without orm' do
6
6
  before :each do
7
7
  Rails3::Assist::Directory.rails_root = fixtures_dir
8
8
 
9
- delete_model(:account) if has_model? :account
9
+ delete_model(:account) # if has_model? :account
10
10
  create_model :account do
11
11
  %q{def index
12
12
  end}
@@ -14,7 +14,36 @@ describe 'model without orm' do
14
14
  end
15
15
 
16
16
  after :each do
17
- # remove_model :account
17
+ remove_model :account
18
+ end
19
+
20
+ context "Non-existant model(s)" do
21
+ it "should not fail trying to remove non-existant models" do
22
+ remove_models :person, :user
23
+ remove_artifacts :model, :person, :user
24
+
25
+ remove_model :person
26
+ remove_artifact :model, :person
27
+ end
28
+
29
+ it "should not find a non-existant model" do
30
+ model_file :person do |person|
31
+ fail "should not find person model!"
32
+ end
33
+
34
+ has_model?(:person).should be_false
35
+ has_models?(:person, :user).should be_false
36
+ end
37
+
38
+ it "should not insert into non-existant model" do
39
+ insert_into_model(:person, :after => 'Hello', :content => 'Yes').should_not be_true
40
+ end
41
+
42
+ it "should not read from non-existant model" do
43
+ read_model :person do |content|
44
+ fail "should not find person content!"
45
+ end.should_not be_true
46
+ end
18
47
  end
19
48
 
20
49
  it "should have an account_model file that contains an index method and two inserted comments" do
@@ -16,7 +16,36 @@ describe 'observer' do
16
16
  end
17
17
 
18
18
  after :each do
19
- # remove_observer :account
19
+ remove_observer :account
20
+ end
21
+
22
+ context "Non-existant observer(s)" do
23
+ it "should not fail trying to remove non-existant observers" do
24
+ remove_observers :person, :user
25
+ remove_artifacts :observer, :person, :user
26
+
27
+ remove_observer :person
28
+ remove_artifact :observer, :person
29
+ end
30
+
31
+ it "should not find a non-existant observer" do
32
+ observer_file :person do |person|
33
+ fail "should not find person observer!"
34
+ end
35
+
36
+ has_observer?(:person).should be_false
37
+ has_observers?(:person, :user).should be_false
38
+ end
39
+
40
+ it "should not insert into non-existant observer" do
41
+ insert_into_observer(:person, :after => 'Hello', :content => 'Yes').should_not be_true
42
+ end
43
+
44
+ it "should not read from non-existant observer" do
45
+ read_observer :person do |content|
46
+ fail "should not find person content!"
47
+ end.should_not be_true
48
+ end
20
49
  end
21
50
 
22
51
  it "should have an account_observer file that contains an index method and two inserted comments" do
@@ -15,7 +15,45 @@ describe 'view API - symbols' do
15
15
  end
16
16
 
17
17
  after :each do
18
- # remove_view :account
18
+ remove_view :account
19
+ end
20
+
21
+ context "Non-existant view(s)" do
22
+
23
+ it "should not fail trying to remove non-existant views" do
24
+ pending "TODO"
25
+
26
+ remove_views :edit, :show, :folder => :person
27
+ remove_artifacts :view, :edit, :show, :folder => :person
28
+
29
+ remove_view :show, :folder => :person
30
+ remove_artifact :view, :show, :folder => :person
31
+ end
32
+
33
+ it "should not find a non-existant view" do
34
+ pending "TODO"
35
+
36
+ view_file :show, :folder => :person do |person|
37
+ fail "should not find person view!"
38
+ end
39
+
40
+ has_view?(:show, :folder => :person).should be_false
41
+ has_views?(:show, :folder => :person).should be_false
42
+ end
43
+
44
+ it "should not insert into non-existant view" do
45
+ pending "TODO"
46
+
47
+ insert_into_view(:show, :folder => :person, :after => 'Hello', :content => 'Yes').should_not be_true
48
+ end
49
+
50
+ it "should not read from non-existant view" do
51
+ pending "TODO"
52
+
53
+ read_view :show, :folder => :person do |content|
54
+ fail "should not find person content!"
55
+ end.should_not be_true
56
+ end
19
57
  end
20
58
 
21
59
  it "should have an account_view file that contains an index method and two inserted comments" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 2
7
8
  - 1
8
- - 5
9
- version: 0.1.5
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-15 00:00:00 +02:00
17
+ date: 2010-09-16 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -140,14 +140,7 @@ files:
140
140
  - lib/rails3_artifactor/rspec/macro.rb
141
141
  - rails3_artifactor.gemspec
142
142
  - spec/fixtures.rb
143
- - spec/fixtures/app/controllers/account_controller.rb
144
- - spec/fixtures/app/helpers/account_helper.rb
145
- - spec/fixtures/app/mailers/account_mailer.rb
146
- - spec/fixtures/app/models/account.rb
147
- - spec/fixtures/app/models/account_observer.rb
148
143
  - spec/fixtures/app/views/account/edit.html.erb
149
- - spec/fixtures/app/views/account/show.html.erb
150
- - spec/fixtures/db/migrations/20100913162614_create_account.rb
151
144
  - spec/rails3_artifactor/artifact/base_spec.rb
152
145
  - spec/rails3_artifactor/artifact/crud/controller_spec.rb
153
146
  - spec/rails3_artifactor/artifact/crud/helper_spec.rb
@@ -206,12 +199,6 @@ signing_key:
206
199
  specification_version: 3
207
200
  summary: Helpers for handling Rails 3 artifacts
208
201
  test_files:
209
- - spec/fixtures/app/controllers/account_controller.rb
210
- - spec/fixtures/app/helpers/account_helper.rb
211
- - spec/fixtures/app/mailers/account_mailer.rb
212
- - spec/fixtures/app/models/account.rb
213
- - spec/fixtures/app/models/account_observer.rb
214
- - spec/fixtures/db/migrations/20100913162614_create_account.rb
215
202
  - spec/fixtures.rb
216
203
  - spec/rails3_artifactor/artifact/base_spec.rb
217
204
  - spec/rails3_artifactor/artifact/crud/controller_spec.rb
@@ -1,8 +0,0 @@
1
- class AccountController < ActionController::Base
2
- # goodbye
3
- # hello
4
-
5
- def index
6
- end
7
-
8
- end
@@ -1,6 +0,0 @@
1
- class AccountHelper
2
-
3
- def index
4
- end
5
-
6
- end
@@ -1,6 +0,0 @@
1
- class AccountMailer < ActionMailer::Base
2
- # goodbye
3
- # hello
4
- def mail_it
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- class Account
2
- # goodbye
3
- # hello
4
- def index
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- class AccountObserver < ActiveRecord::Observer
2
- # goodbye
3
- # hello
4
-
5
- def index
6
- end
7
-
8
- end
@@ -1,4 +0,0 @@
1
- # hello
2
- # goodbye
3
- def index
4
- end
@@ -1,11 +0,0 @@
1
- class CreateAccount < ActiveRecord::Migration
2
- # goodbye
3
- # hello
4
-
5
- def self.up
6
- end
7
-
8
- def self.down
9
- end
10
-
11
- end