cukemin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ Mon May 24
2
+ ----------
3
+ Added controller support
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ Cukemin
2
+ =======
3
+
4
+ Rails generator to generate super lightweight admin controllers complete with cucumber specs!
5
+
6
+ About me
7
+ ========
8
+
9
+ I'm Paul Campbell. I'm an avid Ruby on Rails web developer. Follow my ramblings at [http://www.pabcas.com](http://www.pabcas.com)
10
+
11
+ Follow me on Twitter [http://twitter.com/paulca](http://twitter.com/paulca)
12
+
13
+ Copyright (c) 2010 Paul Campbell, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc 'Run the specs'
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
10
+ t.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ PKG_FILES = FileList[
14
+ '[a-zA-Z]*',
15
+ 'app/**/*',
16
+ 'generators/**/*',
17
+ 'config/*',
18
+ 'lib/**/*',
19
+ 'rails/**/*',
20
+ 'spec/**/*',
21
+ 'features/**/*'
22
+ ]
23
+
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |s|
27
+ s.name = "cukemin"
28
+ s.version = "0.1.0"
29
+ s.author = "Paul Campbell"
30
+ s.email = "paul@rslw.com"
31
+ s.homepage = "http://www.github.com/paulca/cukemin"
32
+ s.platform = Gem::Platform::RUBY
33
+ s.summary = "Simple admin controllers and views, with cucumber features"
34
+ s.files = PKG_FILES.to_a
35
+ s.has_rdoc = false
36
+ s.extra_rdoc_files = ["README.md"]
37
+ end
38
+ rescue LoadError
39
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
40
+ end
41
+
42
+ Jeweler::GemcutterTasks.new
data/cukemin.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cukemin}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paul Campbell"]
12
+ s.date = %q{2010-05-24}
13
+ s.email = %q{paul@rslw.com}
14
+ s.extra_rdoc_files = [
15
+ "README.md"
16
+ ]
17
+ s.files = [
18
+ "CHANGELOG",
19
+ "README.md",
20
+ "Rakefile",
21
+ "cukemin.gemspec",
22
+ "generators/cukemin/USAGE",
23
+ "generators/cukemin/cukemin_generator.rb",
24
+ "generators/cukemin/templates/controller.rb",
25
+ "generators/cukemin/templates/feature.feature",
26
+ "generators/cukemin/templates/views/_form.html.erb",
27
+ "generators/cukemin/templates/views/edit.html.erb",
28
+ "generators/cukemin/templates/views/index.html.erb",
29
+ "generators/cukemin/templates/views/new.html.erb",
30
+ "rails/init.rb",
31
+ "spec/blueprints.rb",
32
+ "spec/cukemin_generator_spec.rb",
33
+ "spec/database.yml",
34
+ "spec/debug.log",
35
+ "spec/schema.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.has_rdoc = false
39
+ s.homepage = %q{http://www.github.com/paulca/cukemin}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.7}
43
+ s.summary = %q{Simple admin controllers and views, with cucumber features}
44
+ s.test_files = [
45
+ "spec/blueprints.rb",
46
+ "spec/cukemin_generator_spec.rb",
47
+ "spec/schema.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ else
57
+ end
58
+ else
59
+ end
60
+ end
61
+
@@ -0,0 +1 @@
1
+ ./script generate cukemin MODELNAME
@@ -0,0 +1,73 @@
1
+ class CukeminGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # puts "#{module_name}, #{model_name}, #{class_name}, #{file_name}, #{file_path}"
5
+ # debugger
6
+ m.class_collisions class_name, "#{class_name}Controller"
7
+
8
+ m.directory controller_dir
9
+ m.template "controller.rb", "#{controller_dir}/#{plural_name}_controller.rb"
10
+
11
+ m.directory view_dir
12
+ m.template "views/index.html.erb", "#{view_dir}/index.html.erb"
13
+ m.template "views/new.html.erb", "#{view_dir}/new.html.erb"
14
+ m.template "views/edit.html.erb", "#{view_dir}/edit.html.erb"
15
+ m.template "views/_form.html.erb", "#{view_dir}/_form.html.erb"
16
+
17
+ m.directory 'features'
18
+ m.template 'feature.feature', "features/#{plural_path_helper}.feature"
19
+ end
20
+ end
21
+
22
+ def split_class_name
23
+ class_name.split('::')
24
+ end
25
+
26
+ def module_parts
27
+ split_class_name[0,split_class_name.length - 1]
28
+ end
29
+
30
+ def module_name
31
+ module_parts.join('::')
32
+ end
33
+
34
+ def form_object
35
+ if module_parts.empty?
36
+ "@#{singular_name}"
37
+ else
38
+ "[#{module_parts.map{ |p| ':' + p.downcase }.join(',')}, @#{singular_name}]"
39
+ end
40
+ end
41
+
42
+ def model_name
43
+ class_name.split('::').last
44
+ end
45
+
46
+ def controller_dir
47
+ "app/controllers/#{File.dirname(file_path)}"
48
+ end
49
+
50
+ def view_dir
51
+ "app/views/#{File.dirname(file_path)}/#{plural_name}"
52
+ end
53
+
54
+ def plural_class_name
55
+ "#{module_name}::#{plural_name.camelize}"
56
+ end
57
+
58
+ def singular_path_helper
59
+ file_path.gsub('/', '_')
60
+ end
61
+
62
+ def plural_path_helper
63
+ "#{File.dirname(file_path).gsub('/', '_')}_#{plural_name}"
64
+ end
65
+
66
+ def after_generate
67
+ puts "
68
+
69
+ Generated!
70
+
71
+ "
72
+ end
73
+ end
@@ -0,0 +1,37 @@
1
+ class <%= plural_class_name %>Controller < ApplicationController
2
+ def index
3
+ @<%= plural_name %> = <%= model_name %>.paginate(:page => params[:page])
4
+ end
5
+
6
+ def new
7
+ @<%= singular_name %> = <%= model_name %>.new
8
+ end
9
+
10
+ def create
11
+ @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>])
12
+ if @<%= singular_name %>.save
13
+ redirect_to <%= plural_path_helper %>_path
14
+ else
15
+ render :new
16
+ end
17
+ end
18
+
19
+ def edit
20
+ @<%= singular_name %> = <%= model_name %>.find(params[:id])
21
+ end
22
+
23
+ def update
24
+ @<%= singular_name %> = <%= model_name %>.find(params[:id])
25
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
26
+ redirect_to <%= plural_path_helper %>_path
27
+ else
28
+ render :edit
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ @<%= singular_name %> = <%= model_name %>.find(params[:id])
34
+ @<%= singular_name %>.destroy
35
+ redirect_to <%= plural_path_helper %>_path
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ Feature: Managing <%= plural_name.titleize %>
2
+ In order to ...
3
+ As a ...
4
+ I want to be able to manage <%= plural_name %>
5
+
6
+ Background:
7
+ Given an admin "edgar@hoover.com" with password "monkeys"
8
+ And I log in as admin "edgar@hoover.com" with password "monkeys"
9
+ And I am on the admin dashboard
10
+
11
+ Scenario: Creating a new <%= singular_name %>
12
+ When I follow "<%= plural_name.titleize %>"
13
+ And I follow "Add New <%= singular_name.titleize %>"
14
+ And I fill in "Name" with "Biggles"
15
+ And I press "Save"
16
+ Then I should see "Biggles"
17
+
18
+ Scenario: Editing an existing <%= singular_name %>
19
+ Given a <%= singular_name %> "Goravia"
20
+ And I am on the admin dashboard
21
+ And I follow "<%= plural_name.titleize %>"
22
+ And I follow "Edit"
23
+ And I fill in "Name" with "Gooravia"
24
+ And I press "Save"
25
+ Then I should see "Gooravia"
26
+ And I should not see "Goravia"
27
+
28
+ Scenario: Deleting an existing <%= singular_name %>
29
+ Given a <%= singular_name %> "Goravia"
30
+ And I am on the admin dashboard
31
+ And I follow "<%= plural_name.titleize %>"
32
+ And I follow "Delete"
33
+ Then I should not see "Goravia"
@@ -0,0 +1,8 @@
1
+ <%%- form_for(<%= form_object %>) do |f| -%>
2
+ <%%= f.error_messages -%>
3
+ <fieldset>
4
+ <%%= f.label :name %> <%%= f.text_field :name %> <br />
5
+ </fieldset>
6
+
7
+ <%%= f.submit "Save" %> or <%%= link_to "Cancel", <%= plural_path_helper %>_path %>
8
+ <%%- end -%>
@@ -0,0 +1,3 @@
1
+ <h2>Edit <%= singular_name.titleize %></h2>
2
+
3
+ <%%= render 'form' %>
@@ -0,0 +1,33 @@
1
+ <h2><%= plural_name.titleize %></h2>
2
+
3
+ <ul>
4
+ <li><%%= link_to 'Add New <%= singular_name.titleize %>', new_<%= singular_path_helper %>_path %></li>
5
+ </ul>
6
+
7
+
8
+ <%%- if @<%= plural_name %>.empty? -%>
9
+ <p>No <%= plural_name %> found.</p>
10
+ <%%- else -%>
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <th>Name</th>
15
+ <th>&nbsp;</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <%%- @<%= plural_name %>.each do |<%= singular_name %>| -%>
20
+ <tr>
21
+ <td>
22
+ <%%= <%= singular_name %>.name %>
23
+ (<%%= link_to "Edit", edit_<%= singular_path_helper %>_path(<%= singular_name %>) -%>)
24
+ </td>
25
+ <td>
26
+ <%%= link_to "Delete", <%= singular_path_helper %>_path(<%= singular_name %>), :method => :delete, :confirm => 'Are you sure?' -%>
27
+ </td>
28
+ </tr>
29
+ <%%- end -%>
30
+ </tbody>
31
+ </table>
32
+ <%%= will_paginate(@<%= plural_name %>) %>
33
+ <%%- end -%>
@@ -0,0 +1,3 @@
1
+ <h2>New <%= singular_name.titleize %></h2>
2
+
3
+ <%%= render 'form' %>
data/rails/init.rb ADDED
File without changes
@@ -0,0 +1,6 @@
1
+ require 'machinist/active_record'
2
+ require 'faker'
3
+ require 'sham'
4
+
5
+ Achievement.blueprint do
6
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+ require 'rails_generator'
3
+ require 'rails_generator/scripts/generate'
4
+
5
+ describe CukeminGenerator do
6
+
7
+ before do
8
+ Rails::Generator::Scripts::Generate.new.run(["cukemin", 'admin/place'], :destination => fake_rails_root, :backtrace => true)
9
+ end
10
+
11
+ let(:controller_file) { fake_rails_root + '/app/controllers/admin/places_controller.rb' }
12
+ let(:index_view_file) { fake_rails_root + '/app/views/admin/places/index.html.erb' }
13
+ let(:edit_view_file) { fake_rails_root + '/app/views/admin/places/edit.html.erb' }
14
+ let(:new_view_file) { fake_rails_root + '/app/views/admin/places/new.html.erb' }
15
+ let(:form_view_file) { fake_rails_root + '/app/views/admin/places/_form.html.erb' }
16
+ let(:feature_file) { fake_rails_root + '/features/admin_places.feature' }
17
+
18
+ it "should create the controller file" do
19
+ File.exists?(controller_file).should be_true
20
+ end
21
+
22
+ it "should output the controller" do
23
+ output = File.read(controller_file)
24
+ output.should match(/Admin::PlacesController < ApplicationController/)
25
+ output.should match(/@place = Place.new/)
26
+ output.should match(/@place = Place.new\(params\[\:place\]\)/)
27
+ output.should match(/if @place.save/)
28
+ output.should match(/redirect_to admin_places_path/)
29
+ output.should match(/@place = Place.find\(params\[:id\]\)/)
30
+ output.should match(/if @place.update_attributes\(params\[:place\]\)/)
31
+ output.should match(/@place.destroy/)
32
+ end
33
+
34
+ it "should create the index view file" do
35
+ File.exists?(index_view_file).should be_true
36
+ end
37
+
38
+ it "should output the index view" do
39
+ output = File.read(index_view_file)
40
+ output.should match(/Places/)
41
+ output.should include(%Q[<li><%= link_to 'Add New Place', new_admin_place_path %></li>])
42
+ output.should match(/if @places.empty?/)
43
+ output.should match(/No places found./)
44
+ output.should match(/@places.each do |place|/)
45
+ output.should match(/place.name/)
46
+ output.should match(/link_to "Edit", edit_admin_place_path\(place\)/)
47
+ output.should include(%Q[link_to "Delete", admin_place_path(place), :method => :delete, :confirm => 'Are you sure?'])
48
+ output.should include("will_paginate(@places)")
49
+ end
50
+
51
+ it "should create the new view file" do
52
+ File.exists?(new_view_file).should be_true
53
+ end
54
+
55
+ it "should output the new view" do
56
+ output = File.read(new_view_file)
57
+ output.should include("New Place")
58
+ end
59
+
60
+ it "should create the edit view file" do
61
+ File.exists?(edit_view_file).should be_true
62
+ end
63
+
64
+ it "should output the new view" do
65
+ output = File.read(edit_view_file)
66
+ output.should include("Edit Place")
67
+ end
68
+
69
+ it "should create the form partial file" do
70
+ File.exists?(form_view_file).should be_true
71
+ end
72
+
73
+ it "should output the form partial" do
74
+ output = File.read(form_view_file)
75
+ output.should include(%Q[<%- form_for([:admin, @place]) do |f| -%>])
76
+ output.should include(%Q[<%= f.submit "Save" %> or <%= link_to "Cancel", admin_places_path %>])
77
+ end
78
+
79
+ it "should create the feature file" do
80
+ File.exists?(feature_file).should be_true
81
+ end
82
+
83
+ it "should output the form partial" do
84
+ output = File.read(feature_file)
85
+ output.should include(%Q[Feature: Managing Places])
86
+ output.should include(%Q[Scenario: Creating a new place])
87
+ output.should include(%Q[When I follow "Places"])
88
+ output.should include(%Q[And I follow "Add New Place"])
89
+ end
90
+
91
+ after do
92
+ FileUtils.rm_r(fake_rails_root)
93
+ end
94
+
95
+
96
+ def fake_rails_root
97
+ File.join(File.dirname(__FILE__), 'spec', 'rails_root')
98
+ end
99
+
100
+ def file_list(dir)
101
+ Dir.glob(File.join(dir, "*"))
102
+ end
103
+
104
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,21 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :database: spec/cukemin.sqlite.db
4
+
5
+ sqlite3:
6
+ :adapter: sqlite3
7
+ :database: spec/cukemin.sqlite3.db
8
+
9
+ postgresql:
10
+ :adapter: postgresql
11
+ :username: postgres
12
+ :password: postgres
13
+ :database: cukemin_test
14
+ :min_messages: ERROR
15
+
16
+ mysql:
17
+ :adapter: mysql
18
+ :host: localhost
19
+ :username: root
20
+ :password: password
21
+ :database: cukemin_test