dream_gens 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Dreamr (James OKelly)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.textile ADDED
@@ -0,0 +1,101 @@
1
+ h1. Dream Gens
2
+
3
+ **Brought to you by rubyloves.me**
4
+
5
+ Please be restful. If you decide you want to leave the golden path you should fork this and make it so you can do your weird, non restful shit. These gens are purely an effort to get back to the original beauty of what drew many to rails, only updated for TDD/BDD using the technologies listed below.
6
+
7
+ Step by step these generators will build the bare bones skeleton for a restfully designed resource to match a feature.
8
+
9
+
10
+ h3. Generators for rapid rails development WITH testing!
11
+
12
+ * HAML Views
13
+ * Cucumber, Capybara, RSpec and Remarkable
14
+
15
+
16
+ h3. To install
17
+ <code>
18
+ git submodule add git://github.com/dreamr/dream_gens.git vender/plugins/dream_gens
19
+ </code>
20
+
21
+ h3. Usage - Dream Generatorsg
22
+
23
+ For Outside-In developing using Dream-gens, cucumber and rspec:
24
+ * generate a feature
25
+ * define the feature
26
+
27
+ h3. Generate a feature
28
+
29
+ <code>./script/generate dream_feature FeatureName Domain</code>
30
+ or
31
+ <code>./script/generate df FeatureName Domain</code>
32
+
33
+ eg.
34
+ <code>./script/generate dream_feature user_logs_in authentication</code>
35
+
36
+ will create:
37
+ * features/_user_logs_in.feature
38
+ * features/step_definitions/authentication_steps.rb
39
+
40
+
41
+ h3. Generate a model, migration and behavior specification file
42
+
43
+
44
+ h2. To generate full rest views and routing
45
+
46
+ <code>./script/generate dream_resource Resource [attribute:type, *]</code>
47
+ or
48
+ <code>./script/generate dr Resource [attribute:type, *]</code>
49
+
50
+ eg.
51
+ <code>./script/generate dream_resource User email:string crypted_password:string</code>
52
+
53
+ will create:
54
+ * app/controllers/users_controller.rb
55
+ * app/models/user.rb
56
+ * app/views/users/
57
+ * partials/_form.html.haml
58
+ * partials/_user.html.haml
59
+ * index.html.haml
60
+ * new.html.haml
61
+ * edit.html.haml
62
+ * show.html.haml
63
+ * config/routes.rb << map.resources :users
64
+ * db/migrate/*****_create_and_index_users.rb
65
+ * spec/controllers/users_controller_spec.rb
66
+ * spec/factories/user_factory.rb
67
+ * spec/models/user_spec.rb
68
+
69
+
70
+ h2. To generate specific rest views and routing
71
+
72
+ <code>./script/generate dream_resource Resource [attribute:type, *] [rest_action, *]</code>
73
+
74
+ eg.
75
+ <code>./script/generate dream_resource User email:string crypted_password:string new create show</code>
76
+
77
+ will create:
78
+ * app/controllers/users_controller.rb
79
+ * app/models/user.rb
80
+ * app/views/users/
81
+ * _form.html.haml
82
+ * new.html.haml
83
+ * show.html.haml
84
+ * config/routes.rb << map.resources :users
85
+ * db/migrate/*****_create_and_index_users.rb
86
+ * spec/controllers/users_controller_spec.rb
87
+ * spec/factories/user_factory.rb
88
+ * spec/models/user_spec.rb
89
+
90
+
91
+ h2. Contributions
92
+
93
+ Maintainer: "dreamr":http://github.com/dreamr
94
+
95
+ Forked and modified from: "meskyanichi":http://github.com/meskyanichi
96
+
97
+ h3. Contributers
98
+
99
+ Fork, make a patch, notify me, get here.
100
+ * "jsilver":http://github.com/jsilver
101
+
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require "rubygems"
2
+ require "cucumber/rake/task"
3
+ require "spec/rake/spectask"
4
+
5
+ Cucumber::Rake::Task.new
6
+
7
+ Spec::Rake::SpecTask.new do |t|
8
+ t.spec_files = FileList['test/**/*_spec.rb']
9
+ end
10
+
11
+ task :default => [:spec, :cucumber]
12
+
13
+ begin
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = "Dream-gens"
17
+ gemspec.summary = "Outside In Dream generators using HAML, RSpec, and FactoryGirl"
18
+ gemspec.description = "Outside In Dream generators using HAML, RSpec, and FactoryGirl"
19
+ gemspec.email = "james@rubyloves.me"
20
+ gemspec.homepage = "http://github.com/dreamr/Dream-gens"
21
+ gemspec.authors = ["Dreamr O'Kelly"]
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ end
26
+
data/dream_gens.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Dreamr
2
+ VERSION = "0.6.0"
3
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'README.textile'))
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + "/../dream_feature/dream_feature_generator"
2
+ module Dreamr
3
+ class DfGenerator < DreamFeatureGenerator ; end
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + "/../dream_resource/dream_resource_generator"
2
+ module Dreamr
3
+ class DrGenerator < DreamResourceGenerator ; end
4
+ end
@@ -0,0 +1,7 @@
1
+ ./script/generate dream_feature feature domain
2
+
3
+ eg. ./script/generate dream_feature user_logs_in authentication
4
+
5
+ will create:
6
+ features/_user_logs_in.feature
7
+ features/step_definitions/authentication_steps.rb
@@ -0,0 +1,26 @@
1
+ module Dreamr
2
+ class DreamFeatureGenerator < Rails::Generator::NamedBase
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+ @feature = runtime_args.shift
7
+ @domain = runtime_args.shift
8
+ end
9
+
10
+ attr_reader :feature, :domain
11
+
12
+ def manifest
13
+ record do |m|
14
+ m.directory 'features/step_definitions'
15
+ m.template "domain_steps.erb", "features/step_definitions/#{domain}_steps.rb"
16
+ m.template "feature.erb", "features/_#{feature}.feature"
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def banner
23
+ "Usage: #{$0} dream_feature feature domain"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ Feature: <%= feature %>
2
+ In order to value
3
+ As a role
4
+ I want feature
5
+
6
+
@@ -0,0 +1,8 @@
1
+ ./script/generate dream_resource resource [attr:type, *] [action, *]
2
+
3
+ eg. ./script/generate dream_resource user email:string new create how
4
+
5
+ will create:
6
+ spec/controllers/users_controller_spec.rb
7
+ spec/models/user_spec.rb
8
+ spec/factories/user_factory.rb
@@ -0,0 +1,180 @@
1
+ require 'active_record'
2
+ require File.dirname(__FILE__) + '/generated_attribute'
3
+
4
+ module Dreamr
5
+ class DreamResourceGenerator < Rails::Generator::NamedBase
6
+ include Rails::Generator
7
+
8
+ default_options :skip_migration => false
9
+
10
+ attr_reader :controller_name,
11
+ :controller_class_path,
12
+ :controller_file_path,
13
+ :controller_class_nesting,
14
+ :controller_class_nesting_depth,
15
+ :controller_class_name,
16
+ :controller_singular_name,
17
+ :controller_plural_name
18
+ alias_method :controller_file_name, :controller_singular_name
19
+ alias_method :controller_table_name, :controller_plural_name
20
+
21
+ attr_accessor :indexes, :rest_actions
22
+
23
+ class << self
24
+ def rest_actions
25
+ %w(:index :show :new :create :edit :update :destroy)
26
+ end
27
+
28
+ def rest_actions_with_views
29
+ %w(:index :show :new :edit)
30
+ end
31
+ end
32
+
33
+ def attributes
34
+ @attributes
35
+ end
36
+
37
+ def rest_actions
38
+ @rest_actions
39
+ end
40
+
41
+ def indexes
42
+ @indexes
43
+ end
44
+
45
+ def initialize(runtime_args, runtime_options = {})
46
+ super
47
+ return unless @args
48
+
49
+ @rest_actions, @indexes, @attributes = [],[],[]
50
+
51
+ @controller_name = @name.pluralize
52
+
53
+ base_name, @controller_class_path, @controller_file_path,
54
+ @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
55
+
56
+ @controller_class_name_without_nesting, @controller_singular_name,
57
+ @controller_plural_name = inflect_names(base_name)
58
+
59
+ gob_nesting_instances
60
+ pop_rest_actions
61
+ pop_and_process_indexes
62
+ process_attributes
63
+ end
64
+
65
+ def manifest
66
+ record do |m|
67
+
68
+ # Check for class naming collisions.
69
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller")
70
+ m.class_collisions(class_path, "#{class_name}")
71
+
72
+ # Controller, helper, views, and spec directories.
73
+ m.directory(File.join('app/models', class_path))
74
+ m.directory(File.join('app/controllers', controller_class_path))
75
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
76
+ m.directory(File.join('spec/controllers', controller_class_path))
77
+ m.directory(File.join('spec/models', class_path))
78
+ m.directory(File.join('spec/factories', class_path))
79
+ m.directory(File.join('db/migrate'))
80
+
81
+ m.template "spec/controller_spec.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
82
+ m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
83
+
84
+ m.template "model.rb", "app/models/#{singular_name}.rb"
85
+ m.template "spec/model_spec.rb", "spec/models/#{singular_name}_spec.rb"
86
+ m.template "spec/factory.rb", "spec/factories/#{singular_name}_factory.rb"
87
+
88
+ # Create routes
89
+ m.route_resources plural_name
90
+
91
+ # Create migration
92
+ m.migration_template 'migration.rb', "db/migrate", :assigns => { :indexes => @indexes }, :migration_file_name => "create_#{plural_name}"
93
+
94
+ install_views(m)
95
+ end
96
+ end
97
+
98
+ protected
99
+
100
+ def pop_rest_actions
101
+ @args.each do |arg|
102
+ next unless is_action?(arg)
103
+ @rest_actions << arg
104
+ end
105
+ @args = (@args-@rest_actions)
106
+ end
107
+
108
+ def process_attributes
109
+ @args.each do |arg|
110
+ next unless is_attribute?(arg)
111
+ name, type = arg.split(":")
112
+ @attributes << GeneratedAttribute.new(name, type)
113
+ end
114
+ end
115
+
116
+ def pop_and_process_indexes
117
+ @args.each do |arg|
118
+ next unless is_attribute?(arg)
119
+ attr_vals = arg.split(':')
120
+ process_index(attr_vals) if attr_vals.length == 3 && attr_vals[2] == "index"
121
+ end
122
+ @args.flatten.each {|arg| arg.gsub(':index','')}
123
+ end
124
+
125
+ def process_index(attr_vals)
126
+ @indexes << attr_vals[0]
127
+ end
128
+
129
+ def gob_nesting_instances
130
+ if @controller_class_nesting.empty?
131
+ @controller_class_name = @controller_class_name_without_nesting
132
+ else
133
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
134
+ end
135
+ end
136
+
137
+ def is_attribute?(val)
138
+ val =~ /\w:\w/ || val =~ /\w:\w:\w/
139
+ end
140
+
141
+ def is_action?(val)
142
+ DreamResourceGenerator.rest_actions.include?(val)
143
+ end
144
+
145
+ def install_views(manifest)
146
+ if @rest_actions.empty?
147
+ views = DreamResourceGenerator.rest_actions_with_views
148
+ else
149
+ views = @rest_actions.reject {|view| !DreamResourceGenerator.rest_actions_with_views.include?(view) }
150
+ end
151
+
152
+ views.each do |view|
153
+ sym = view.to_sym
154
+ clean = view.gsub(':', '')
155
+
156
+ unless File.exists?("#{@app_root}/app/views/#{plural_name}/_form.html.haml")
157
+ manifest.template "views/_form.html.haml",
158
+ "app/views/#{plural_name}/_form.html.haml" if [:new, :edit].include?(clean.to_sym) || @rest_actions.empty?
159
+ end
160
+
161
+ manifest.template "views/#{clean}.html.haml",
162
+ "app/views/#{plural_name}/#{clean}.html.haml"
163
+ end
164
+ end
165
+
166
+
167
+ # Override with your own usage banner.
168
+ def banner
169
+ "Usage: #{$0} dream_resource ResourceName [field:type field:type]"
170
+ end
171
+
172
+ def add_options!(opt)
173
+ opt.separator ''
174
+ opt.separator 'Options:'
175
+ opt.on("--skip-migration",
176
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
177
+ end
178
+
179
+ end
180
+ end
@@ -0,0 +1,44 @@
1
+ module Rails
2
+ module Generator
3
+
4
+ class GeneratedAttribute
5
+ def default_value
6
+ @default_value ||= case type
7
+ when :int, :integer then "\"1\""
8
+ when :float then "\"1.5\""
9
+ when :decimal then "\"9.99\""
10
+ when :datetime, :timestamp, :time then "Time.now"
11
+ when :date then "Date.today"
12
+ when :string, :text then "\"value for #{@name}\""
13
+ when :boolean then "false"
14
+ else
15
+ ""
16
+ end
17
+ end
18
+
19
+ def default_factory_value
20
+ @default_factory_value ||= case type
21
+ when :int, :integer then "1"
22
+ when :float then "1.5"
23
+ when :decimal then "9.99"
24
+ when :datetime, :timestamp, :time then "Time.now"
25
+ when :date then "Date.today"
26
+ when :string, :text then "\"value for #{@name}\""
27
+ when :boolean then "false"
28
+ else
29
+ "\"\""
30
+ end
31
+ end
32
+
33
+ def name_or_reference
34
+ if ::Rails::VERSION::STRING >= '2.2'
35
+ reference? ? :"#{name}_id" : name
36
+ else
37
+ name
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,114 @@
1
+ class <%= plural_name.capitalize %>Controller < ApplicationController
2
+ <% action = <<-EOS
3
+
4
+ # GET /#{plural_name}
5
+ # GET /#{plural_name}.xml
6
+ def index
7
+ @#{plural_name} = #{singular_name.capitalize}.all
8
+
9
+ respond_to do |format|
10
+ format.html # index.html.haml
11
+ format.xml { render :xml => @#{plural_name} }
12
+ end
13
+ end
14
+ EOS
15
+ -%>
16
+ <%= action if rest_actions.nil? || rest_actions.include?(":index") -%>
17
+ <% action = <<-EOS
18
+
19
+ # GET /#{plural_name}/1
20
+ # GET /#{plural_name}/1.xml
21
+ def show
22
+ @#{singular_name} = #{singular_name.capitalize}.find(params[:id])
23
+
24
+ respond_to do |format|
25
+ format.html # show.html.erb
26
+ format.xml { render :xml => @#{singular_name} }
27
+ end
28
+ end
29
+ EOS
30
+ -%>
31
+ <%= action if rest_actions.nil? || rest_actions.include?(":show") -%>
32
+ <% action = <<-EOS
33
+
34
+ # GET /#{plural_name}/new
35
+ # GET /#{plural_name}/new.xml
36
+ def new
37
+ @#{singular_name} = #{singular_name.capitalize}.new
38
+
39
+ respond_to do |format|
40
+ format.html # new.html.erb
41
+ format.xml { render :xml => @#{singular_name} }
42
+ end
43
+ end
44
+ EOS
45
+ -%>
46
+ <%= action if rest_actions.nil? || rest_actions.include?(":new") -%>
47
+ <% action = <<-EOS
48
+
49
+ # GET /#{plural_name}/1/edit
50
+ def edit
51
+ @#{singular_name} = #{singular_name.capitalize}.find(params[:id])
52
+ end
53
+ EOS
54
+ -%>
55
+ <%= action if rest_actions.nil? || rest_actions.include?(":edit") -%>
56
+ <% action = <<-EOS
57
+
58
+ # POST /#{plural_name}
59
+ # POST /#{plural_name}.xml
60
+ def create
61
+ @#{singular_name} = #{singular_name.capitalize}.new(params[:#{singular_name}])
62
+
63
+ respond_to do |format|
64
+ if @#{singular_name}.save
65
+ flash[:notice] = '#{singular_name.capitalize} was successfully created.'
66
+ format.html { redirect_to(@#{singular_name}) }
67
+ format.xml { render :xml => @#{singular_name}, :status => :created, :location => @#{singular_name} }
68
+ else
69
+ format.html { render :action => "new" }
70
+ format.xml { render :xml => @#{singular_name}.errors, :status => :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+ EOS
75
+ -%>
76
+ <%= action if rest_actions.nil? || rest_actions.include?(":create") -%>
77
+ <% action = <<-EOS
78
+
79
+ # PUT /#{plural_name}/1
80
+ # PUT /#{plural_name}/1.xml
81
+ def update
82
+ @#{singular_name} = #{singular_name.capitalize}.find(params[:id])
83
+
84
+ respond_to do |format|
85
+ if @#{singular_name}.update_attributes(params[:#{singular_name}])
86
+ flash[:notice] = '#{singular_name.capitalize} was successfully updated.'
87
+ format.html { redirect_to(@#{singular_name}) }
88
+ format.xml { head :ok }
89
+ else
90
+ format.html { render :action => "edit" }
91
+ format.xml { render :xml => @#{singular_name}.errors, :status => :unprocessable_entity }
92
+ end
93
+ end
94
+ end
95
+ EOS
96
+ -%>
97
+ <%= action if rest_actions.nil? || rest_actions.include?(":update") -%>
98
+ <% action = <<-EOS
99
+
100
+ # DELETE /#{plural_name}/1
101
+ # DELETE /#{plural_name}/1.xml
102
+ def destroy
103
+ @#{singular_name} = #{singular_name.capitalize}.find(params[:id])
104
+ @#{singular_name}.destroy
105
+
106
+ respond_to do |format|
107
+ format.html { redirect_to(#{plural_name}_url) }
108
+ format.xml { head :ok }
109
+ end
110
+ end
111
+ EOS
112
+ -%>
113
+ <%= action if rest_actions.nil? || rest_actions.include?(":destroy") -%>
114
+ end
@@ -0,0 +1,17 @@
1
+ class Create<%= plural_name.capitalize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= plural_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ <%= "t.#{attribute.try(:type)} :#{attribute.try(:name)}" %>
6
+ <% end -%>
7
+ end
8
+ <% for index in indexes -%>
9
+ add_index :<%= plural_name %>, :<%= index %>
10
+ <% end -%>
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= plural_name %>
15
+ end
16
+ end
17
+
@@ -0,0 +1,4 @@
1
+ class <%= singular_name.capitalize %> < ActiveRecord::Base
2
+ attr_accessible
3
+ end
4
+
@@ -0,0 +1,125 @@
1
+ require 'spec/spec_helper'
2
+ <% spec = <<-EOS
3
+
4
+ describe #{plural_name.capitalize}Controller do
5
+ mock_models :#{singular_name}
6
+
7
+ describe :get => :index do
8
+ expects :all, :on => #{singular_name.capitalize}, :returns => [mock_#{singular_name}, mock_#{singular_name}]
9
+
10
+ should_assign_to :#{plural_name}
11
+ should_render_template :index
12
+ end
13
+ end
14
+ EOS
15
+ -%>
16
+ <%= spec if rest_actions.nil? || rest_actions.include?(":new") -%>
17
+
18
+ <% spec = <<-EOS
19
+
20
+ describe #{plural_name.capitalize}Controller do
21
+ describe :get => :new do
22
+ expects :new, :on => #{singular_name.capitalize}, :returns => #{singular_name.capitalize}.new
23
+
24
+ should_assign_to :#{singular_name}
25
+ should_render_template :new
26
+ end
27
+ end
28
+ EOS
29
+ -%>
30
+ <%= spec if rest_actions.nil? || rest_actions.include?(":new") -%>
31
+ <% spec = <<-EOS
32
+
33
+ describe #{plural_name.capitalize}Controller do
34
+ mock_models :#{singular_name}
35
+
36
+ describe :get => :edit, :id => 37 do
37
+ expects :find, :on => #{singular_name.capitalize}, :with => '37', :returns => mock_#{singular_name}
38
+
39
+ should_assign_to :#{singular_name}, :with => mock_#{singular_name}
40
+ should_render_template :edit
41
+ end
42
+ end
43
+ EOS
44
+ -%>
45
+ <%= spec if rest_actions.nil? || rest_actions.include?(":edit") -%>
46
+ <% spec = <<-EOS
47
+
48
+ describe #{plural_name.capitalize}Controller do
49
+ mock_models :#{singular_name}
50
+
51
+ describe :post => :create do
52
+ expects :new, :on => #{singular_name.capitalize}, :returns => mock_#{singular_name}
53
+ expects :save, :on => mock_#{singular_name}, :returns => false
54
+
55
+ should_assign_to :#{singular_name}, :with => mock_#{singular_name}
56
+ should_render_template :new
57
+ end
58
+ end
59
+ EOS
60
+ -%>
61
+ <%= spec if rest_actions.nil? || rest_actions.include?(":create") -%>
62
+ <% spec = <<-EOS
63
+
64
+ describe #{plural_name.capitalize}Controller do
65
+ mock_models :#{singular_name}
66
+
67
+ describe :post => :create, :#{singular_name} => { :these => 'params' } do
68
+ expects :new, :on => #{singular_name.capitalize}, :returns => mock_#{singular_name}
69
+ expects :save, :on => mock_#{singular_name}, :returns => true
70
+
71
+ should_assign_to :#{singular_name}, :with => mock_#{singular_name}
72
+ should_redirect_to { #{singular_name}_url(mock_#{singular_name}) }
73
+ end
74
+ end
75
+ EOS
76
+ -%>
77
+ <%= spec if rest_actions.nil? || rest_actions.include?(":create") -%>
78
+ <% spec = <<-EOS
79
+
80
+ describe #{plural_name.capitalize}Controller do
81
+ mock_models :#{singular_name}
82
+
83
+ describe :put => :update, :id => '37' do
84
+ expects :find, :on => #{singular_name.capitalize}, :with => '37', :returns => mock_#{singular_name}
85
+ expects :update_attributes, :on => mock_#{singular_name}, :returns => false
86
+
87
+ should_assign_to :#{singular_name}, :with => mock_#{singular_name}
88
+ should_render_template :edit
89
+ end
90
+ end
91
+ EOS
92
+ -%>
93
+ <%= spec if rest_actions.nil? || rest_actions.include?(":update") -%>
94
+ <% spec = <<-EOS
95
+
96
+ describe #{plural_name.capitalize}Controller do
97
+ mock_models :#{singular_name}
98
+
99
+ describe :put => :update, :id => '37' do
100
+ expects :find, :on => #{singular_name.capitalize}, :with => '37', :returns => mock_#{singular_name}
101
+ expects :update_attributes, :on => mock_#{singular_name}, :returns => true
102
+
103
+ should_assign_to :#{singular_name}, :with => mock_#{singular_name}
104
+ should_redirect_to { #{singular_name}_url(mock_#{singular_name}) }
105
+ end
106
+ end
107
+ EOS
108
+ -%>
109
+ <%= spec if rest_actions.nil? || rest_actions.include?(":update") -%>
110
+ <% spec = <<-EOS
111
+
112
+ describe #{plural_name.capitalize}Controller do
113
+ mock_models :#{singular_name}
114
+
115
+ describe :delete => :destroy, :id => '37' do
116
+ expects :find, :on => #{singular_name.capitalize}, :with => '37', :returns => mock_#{singular_name}
117
+ expects :destroy, :on => mock_#{singular_name}
118
+
119
+ should_assign_to :#{singular_name}, :with => mock_#{singular_name}
120
+ should_redirect_to { #{plural_name}_url }
121
+ end
122
+ end
123
+ EOS
124
+ -%>
125
+ <%= spec if rest_actions.nil? || rest_actions.include?(":destroy") -%>
@@ -0,0 +1,7 @@
1
+ require 'faker'
2
+
3
+ Factory.define :<%= singular_name %> do |<%= singular_name %>|
4
+ <% attributes.each do |attribute| -%>
5
+ <%= "#{singular_name}.#{attribute.try(:name)} #{attribute.try(:default_factory_value)}" if attribute %>
6
+ <% end -%>
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= singular_name.capitalize %> do
4
+ before(:each) do
5
+ @<%= singular_name %> = Factory(:<%= singular_name %>)
6
+ end
7
+
8
+ it "should be valid from factory" do
9
+ @<%= singular_name %>.should be_valid
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ - semantic_form_for(resource) do |f|
2
+ - f.inputs do
3
+ <% attributes.each do |attribute| -%>
4
+ <%= "= f.input #{attribute.try(:name)}" if attribute %>
5
+ <% end -%>
6
+ - f.buttons do
7
+ = f.commit_button
@@ -0,0 +1,3 @@
1
+ %h1 Editing <%= singular_name %>
2
+
3
+ = render :partial 'form', :object => @<%= singular_name %>
@@ -0,0 +1,13 @@
1
+ %h1 Listing <%= plural_name %>
2
+
3
+ %table
4
+ %tr
5
+ <% attributes.each do |attribute| -%>
6
+ <%= "%th #{attribute.try(:column).try(:human_name)}" if attribute %>
7
+ <% end -%>
8
+
9
+ - for <%= singular_name %> in @<%= plural_name %>
10
+ %tr
11
+ <% attributes.each do |attribute| -%>
12
+ <%= "%td=#{singular_name}.#{attribute.try(:name)}" %>
13
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ %h1 Creating <%= singular_name %>
2
+
3
+ = render :partial 'form', :object => <%= singular_name.capitalize %>.new
@@ -0,0 +1,6 @@
1
+ <% attributes.each do |attribute| -%>
2
+ %p
3
+ %b <%= attribute.try(:column).try(:human_name) %>:
4
+ <%= "= @#{singular_name}.#{attribute.try(:name)}" if attribute %>
5
+
6
+ <% end -%>
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dream_gens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Dreamr (James OKelly)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-01 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: " Dream Generators provides rapid rails development with testing!\n"
17
+ email: james@rubyloves.me
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - README.textile
27
+ - Rakefile
28
+ - install.rb
29
+ - dream_gens.rb
30
+ - rails_generators/df/df_generator.rb
31
+ - rails_generators/dr/dr_generator.rb
32
+ - rails_generators/dream_feature/dream_feature_generator.rb
33
+ - rails_generators/dream_feature/templates/domain_steps.erb
34
+ - rails_generators/dream_feature/templates/feature.erb
35
+ - rails_generators/dream_feature/USAGE
36
+ - rails_generators/dream_resource/dream_resource_generator.rb
37
+ - rails_generators/dream_resource/generated_attribute.rb
38
+ - rails_generators/dream_resource/templates/controller.rb
39
+ - rails_generators/dream_resource/templates/migration.rb
40
+ - rails_generators/dream_resource/templates/model.rb
41
+ - rails_generators/dream_resource/templates/spec/controller_spec.rb
42
+ - rails_generators/dream_resource/templates/spec/factory.rb
43
+ - rails_generators/dream_resource/templates/spec/model_spec.rb
44
+ - rails_generators/dream_resource/templates/views/_form.html.haml
45
+ - rails_generators/dream_resource/templates/views/edit.html.haml
46
+ - rails_generators/dream_resource/templates/views/index.html.haml
47
+ - rails_generators/dream_resource/templates/views/new.html.haml
48
+ - rails_generators/dream_resource/templates/views/show.html.haml
49
+ - rails_generators/dream_resource/USAGE
50
+ has_rdoc: true
51
+ homepage: http://wiki.github.com/dreamr/dream_gens/
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "1.3"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Dream Generators provides rapid rails development with testing!
78
+ test_files: []
79
+