raygun 0.0.3 → 0.0.4

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.
Files changed (39) hide show
  1. data/.gitignore +1 -0
  2. data/.rbenv-version +1 -0
  3. data/.rvmrc +1 -1
  4. data/README.md +34 -11
  5. data/TODO.md +1 -1
  6. data/bin/raygun +6 -7
  7. data/generators/application_template.rb +5 -0
  8. data/generators/simplecov/simplecov.rb +25 -0
  9. data/generators/simplecov/simplecov_template.rb +11 -0
  10. data/generators/simplecov/spec/support/simplecov.rb +25 -0
  11. data/generators/simplecov/tasks/coverage.rake +12 -0
  12. data/lib/raygun/app_builder.rb +53 -12
  13. data/lib/raygun/generators/app_generator.rb +45 -48
  14. data/lib/raygun/helpers/ruby_version_helpers.rb +52 -0
  15. data/lib/raygun/raygun.rb +11 -0
  16. data/lib/raygun/version.rb +1 -1
  17. data/templates/Gemfile_customized +7 -0
  18. data/templates/Guardfile_customized +18 -0
  19. data/templates/Procfile +1 -0
  20. data/templates/README.md.erb +3 -3
  21. data/templates/_app/controllers/user_sessions_controller.rb +1 -0
  22. data/templates/_app/models/ability.rb +36 -0
  23. data/templates/_app/models/user.rb +1 -1
  24. data/templates/_db/sample_data.rb +8 -1
  25. data/templates/_lib/tasks/coverage.rake +12 -0
  26. data/templates/_lib/tasks/db.rake +1 -1
  27. data/templates/_lib/tasks/spec.rake +18 -0
  28. data/templates/_lib/templates/rails/scaffold_controller/controller.rb +45 -0
  29. data/templates/_lib/templates/slim/scaffold/_form.html.slim +1 -1
  30. data/templates/_lib/templates/slim/scaffold/index.html.slim +8 -7
  31. data/templates/_lib/templates/slim/scaffold/show.html.slim +10 -8
  32. data/templates/_spec/factories/users.rb +5 -0
  33. data/templates/_spec/javascripts/example_spec.js.coffee +20 -0
  34. data/templates/_spec/javascripts/spec.css +3 -0
  35. data/templates/_spec/javascripts/spec.js.coffee +2 -0
  36. data/templates/_spec/models/ability_spec.rb +36 -0
  37. data/templates/rbenv-version.erb +1 -0
  38. metadata +21 -3
  39. data/templates/_lib/email_validator.rb +0 -9
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .local
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p286-perf
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3-p194@raygun --create
1
+ rvm use 1.9.3-p286@raygun --create
data/README.md CHANGED
@@ -20,6 +20,7 @@ Major tools/libraries:
20
20
  * Cancan
21
21
  * RSpec
22
22
  * Factory Girl
23
+ * Jasmine
23
24
  * Guard
24
25
 
25
26
  And many tweaks, patterns and common recipes.
@@ -27,32 +28,40 @@ And many tweaks, patterns and common recipes.
27
28
  ## Projects Goals
28
29
 
29
30
  Raygun...
31
+
30
32
  * should generate a new rails application that's ready for feature development immediately.
31
33
  * should generate an application that has best practices that apply to most projects baked in.
32
34
  * is a forum for discussing what should or should not be included as part of a standard stack.
33
35
 
34
36
  ## Installation
35
37
 
36
- $ gem install raygun
38
+ $ gem install raygun
39
+
40
+ ## Prerequisites
41
+
42
+ Be sure you met these requirements before using raygun, otherwise you won't make it very far (misfire!).
43
+
44
+ * Ruby 1.9.2+ (rvm and rbenv supported)
45
+ * PostgreSQL 9.x with superuser 'postgres' with no password (```createuser -s postgres```)
46
+ * PhantomJS for JavaScript testing (```brew install phantomjs```)
37
47
 
38
48
  ## Usage
39
49
 
40
- $ raygun your-project
50
+ $ raygun your-project
41
51
 
42
52
  Once your project is baked out, you can easily kick the wheels:
43
53
 
44
- $ cd your-project
54
+ $ cd your-project
45
55
 
46
- # Prep the database
47
- $ rake db:create db:migrate db:test:prepare
56
+ # Prepare the database: schema and reference / sample data
57
+ $ rake db:migrate db:seed db:sample_data
48
58
 
49
- # Run the specs
50
- $ rake spec
59
+ # Run the specs
60
+ $ rake
51
61
 
52
- # Load some sample data, fire up the app and open it in a browser
53
- $ rake db:seed db:sample_data
54
- $ rails s
55
- $ open http://0.0.0.0:3000
62
+ # Fire up the app and open it in a browser
63
+ $ foreman start
64
+ $ open http://0.0.0.0:3000
56
65
 
57
66
  ## Contributing
58
67
 
@@ -61,3 +70,17 @@ Once your project is baked out, you can easily kick the wheels:
61
70
  3. Commit your changes (`git commit -am 'Add some feature'`)
62
71
  4. Push to the branch (`git push origin my-new-feature`)
63
72
  5. Create new Pull Request
73
+
74
+ ### Development
75
+
76
+ Generate an example app using your local development version of raygun
77
+
78
+ ./bin/raygun tmp/example_app
79
+
80
+ ### Customizing the generated Rails app
81
+
82
+ Changes which can be applied on top of an existing Rails app should be added as `foo_template.rb` files
83
+ in `raygun/generators/foo/`.
84
+
85
+ Changes which must be performed during the creation of the Rails app should be added to `lib/raygun/app_builder.rb`
86
+ and called from an appropriate step in `lib/raygun/generators/app_generator.rb`.
data/TODO.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TODOs
2
2
 
3
- Looking for inspiration? Here are some ideas for things that still could be done.
3
+ Looking for inspiration? Here are some ideas for things that still could be done. Don't forget to check the open issus too.
4
4
 
5
5
  * Cleanup/refactor raygun code (a few simple helpers would help out a whole lot)
6
6
  * Automated testing of raygun (e.g. generate an app and run its specs?)
data/bin/raygun CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.join('..', 'lib', 'raygun', 'generators', 'app_generator'), File.dirname(__FILE__))
4
- require File.expand_path(File.join('..', 'lib', 'raygun', 'actions'), File.dirname(__FILE__))
5
- require File.expand_path(File.join('..', 'lib', 'raygun', 'app_builder'), File.dirname(__FILE__))
6
-
2
+ require File.expand_path(File.join('..', 'lib', 'raygun', 'raygun'), File.dirname(__FILE__))
3
+ Raygun::AppGenerator.launch_path(Dir.pwd)
7
4
  templates_root = File.expand_path(File.join('..', 'templates'), File.dirname(__FILE__))
8
5
  Raygun::AppGenerator.source_root templates_root
9
- Raygun::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
6
+ Raygun::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root
7
+ Raygun::AppGenerator.source_paths << templates_root
8
+ Raygun::AppGenerator.source_paths << File.expand_path(File.join('..', 'generators'), File.dirname(__FILE__))
10
9
 
11
- Raygun::AppGenerator.start
10
+ Raygun::AppGenerator.start ARGV.concat ['-m', 'generators/application_template.rb']
@@ -0,0 +1,5 @@
1
+ Dir.chdir(File.dirname(__FILE__)) do
2
+ Dir.glob("*/*_template.rb") do |template|
3
+ apply template unless template == File.basename(__FILE__)
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+
4
+ # Writes the coverage stat to a file to be used by Cane.
5
+ class SimpleCov::Formatter::QualityFormatter
6
+ def format(result)
7
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
8
+ File.open("coverage/covered_percent", "w") do |f|
9
+ f.puts result.source_files.covered_percent.to_f
10
+ end
11
+ end
12
+ end
13
+ SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
14
+
15
+ SimpleCov.start do
16
+ add_filter '/spec/'
17
+ add_filter '/config/'
18
+ add_filter '/vendor/'
19
+ add_group 'Models', 'app/models'
20
+ add_group 'Controllers', 'app/controllers'
21
+ add_group 'Helpers', 'app/helpers'
22
+ add_group 'Views', 'app/views'
23
+ add_group 'Mailers', 'app/mailers'
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ insert_into_file 'spec/spec_helper.rb',
2
+ "require File.expand_path('../support/simplecov', __FILE__)\n",
3
+ after: "ENV[\"RAILS_ENV\"] ||= \'test\'\n"
4
+
5
+ #gem_group :test, :development do
6
+ # gem 'simplecov'
7
+ #end
8
+ uncomment_lines 'Gemfile', /simplecov/
9
+
10
+ copy_file 'simplecov/tasks/coverage.rake', 'lib/tasks/coverage.rake'
11
+ copy_file 'simplecov/spec/support/simplecov.rb', 'spec/support/simplecov.rb'
@@ -0,0 +1,25 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+
4
+ # Writes the coverage stat to a file to be used by Cane.
5
+ class SimpleCov::Formatter::QualityFormatter
6
+ def format(result)
7
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
8
+ File.open("coverage/covered_percent", "w") do |f|
9
+ f.puts result.source_files.covered_percent.to_f
10
+ end
11
+ end
12
+ end
13
+ SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
14
+
15
+ SimpleCov.start do
16
+ add_filter '/spec/'
17
+ add_filter '/config/'
18
+ add_filter '/vendor/'
19
+ add_group 'Models', 'app/models'
20
+ add_group 'Controllers', 'app/controllers'
21
+ add_group 'Helpers', 'app/helpers'
22
+ add_group 'Views', 'app/views'
23
+ add_group 'Mailers', 'app/mailers'
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ namespace :spec do
2
+ task :enable_coverage do
3
+ ENV['COVERAGE'] = '1'
4
+ end
5
+
6
+ desc 'Executes specs with code coverage reports'
7
+ task coverage: :enable_coverage do
8
+ Rake::Task[:spec].invoke
9
+ end
10
+ end
11
+
12
+ Rake::Task['spec'].enhance ['spec:enable_coverage']
@@ -54,12 +54,18 @@ module Raygun
54
54
  template 'rvmrc.erb', '.rvmrc', rvm_ruby: rvm_ruby
55
55
  end
56
56
 
57
+ def configure_rbenv
58
+ template 'rbenv-version.erb', '.rbenv-version', rbenv_ruby: rbenv_ruby
59
+ end
60
+
57
61
  def configure_gemfile
58
62
  run 'gem install bundler'
59
63
  copy_file 'Gemfile_customized', 'Gemfile', force: true
60
64
  end
61
65
 
62
66
  def setup_generators
67
+ directory '_lib/templates/rails', 'lib/templates/rails'
68
+
63
69
  %w(_form index show new edit).each do |view|
64
70
  template = "lib/templates/slim/scaffold/#{view}.html.slim"
65
71
  remove_file template
@@ -71,10 +77,10 @@ module Raygun
71
77
  generators_config = <<-RUBY
72
78
 
73
79
  config.generators do |generate|
74
- generate.stylesheets false
75
- #generate.helpers false
76
- generate.route_specs false
77
- #generate.view_specs false
80
+ generate.stylesheets false
81
+ #generate.helpers false
82
+ generate.routing_specs false
83
+ #generate.view_specs false
78
84
  end
79
85
 
80
86
  RUBY
@@ -116,6 +122,11 @@ RUBY
116
122
  copy_file '_spec/support/accept_values.rb', 'spec/support/accept_values.rb'
117
123
  end
118
124
 
125
+ def add_js_testing
126
+ directory '_spec/javascripts', 'spec/javascripts'
127
+ copy_file '_lib/tasks/spec.rake', 'lib/tasks/spec.rake'
128
+ end
129
+
119
130
  def configure_time_zone
120
131
  'config/application.rb'.tap do |fn|
121
132
  #inject_into_file fn, ' config.active_record.default_timezone = :utc\n', after: "'Central Time (US & Canada)'\n"
@@ -138,12 +149,6 @@ RUBY
138
149
  end
139
150
  end
140
151
 
141
- def add_email_validator
142
- # CN: I'm not thrilled with this use of the lib directory, but it's not that unusual. Would love to hear what
143
- # other folks think about where such things should live.
144
- copy_file '_lib/email_validator.rb', 'lib/email_validator.rb'
145
- end
146
-
147
152
  def setup_simple_form
148
153
  generate 'simple_form:install --bootstrap -s'
149
154
 
@@ -169,8 +174,10 @@ RUBY
169
174
  copy_file '_spec/factories/users.rb', 'spec/factories/users.rb', force: true
170
175
  copy_file '_spec/models/user_spec.rb', 'spec/models/user_spec.rb', force: true
171
176
 
177
+ gsub_file 'spec/controllers/users_controller_spec.rb', 'login_user build :user', 'login_user build :admin'
178
+
172
179
  inject_into_file 'app/controllers/users_controller.rb',
173
- "\n before_filter :require_login\n\n",
180
+ "\n before_filter :require_login\n",
174
181
  after: "UsersController < ApplicationController\n"
175
182
 
176
183
  # User mailer (has to happen before sorcery config changes)
@@ -246,7 +253,34 @@ RUBY
246
253
 
247
254
  copy_file '_app/views/password_resets/edit.html.slim',
248
255
  'app/views/password_resets/edit.html.slim'
256
+ end
257
+
258
+ def setup_authorization
259
+ generate 'migration add_admin_to_users admin:boolean'
260
+
261
+ copy_file '_app/models/ability.rb', 'app/models/ability.rb'
262
+ copy_file '_spec/models/ability_spec.rb', 'spec/models/ability_spec.rb'
249
263
 
264
+ inject_into_file 'app/controllers/application_controller.rb',
265
+ " check_authorization\n",
266
+ after: "protect_from_forgery\n"
267
+
268
+ append_to_file 'config/environments/test.rb', 'Sorcery::CryptoProviders::BCrypt.cost = 1'
269
+ end
270
+
271
+ def setup_default_rake_task
272
+ append_file 'Rakefile' do
273
+ "\ntask(:default).clear\ntask default: ['spec', 'spec:javascripts']"
274
+ end
275
+ end
276
+
277
+ def setup_guard
278
+ copy_file 'Guardfile_customized', 'Guardfile'
279
+ run 'bundle exec guard init jasmine'
280
+ end
281
+
282
+ def setup_logging
283
+ inject_into_file 'config.ru', "$stdout.sync = true\n", before: 'run ExampleApp::Application'
250
284
  end
251
285
 
252
286
  def setup_stylesheets
@@ -265,12 +299,19 @@ RUBY
265
299
  copy_file '_db/sample_data.rb', 'db/sample_data.rb'
266
300
  end
267
301
 
302
+ def copy_procfile
303
+ copy_file 'Procfile'
304
+ end
305
+
268
306
  def remove_routes_comment_lines
269
307
  replace_in_file 'config/routes.rb', /Application\.routes\.draw do.*end/m, "Application.routes.draw do\nend"
270
308
  end
271
309
 
272
310
  def convert_to_19_hash_syntax
273
- run 'hash_syntax -n'
311
+ original_destination_root = destination_root
312
+ inside(Raygun::AppGenerator.launch_path) do
313
+ run "find #{original_destination_root} -name '*.rb' | xargs hash_syntax -n"
314
+ end
274
315
  end
275
316
 
276
317
  def consistent_quoting
@@ -1,9 +1,12 @@
1
- require 'rails/generators'
2
- require 'rails/generators/rails/app/app_generator'
3
- require 'rvm'
4
-
5
1
  module Raygun
6
2
  class AppGenerator < Rails::Generators::AppGenerator
3
+ include Raygun::RubyVersionHelpers
4
+
5
+ # set and get raygun launch path
6
+ def self.launch_path(path=nil)
7
+ @_launch_path = path if path
8
+ @_launch_path
9
+ end
7
10
 
8
11
  class_option :database, type: :string, aliases: '-d', default: 'postgresql',
9
12
  desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
@@ -17,28 +20,24 @@ module Raygun
17
20
  end
18
21
 
19
22
  def raygun_customization
20
- rvm_original_env = RVM.current.expanded_name
21
-
22
- invoke :remove_files_we_dont_need
23
- invoke :remove_routes_comment_lines
24
- invoke :setup_development_environment
25
- invoke :setup_production_environment
26
- invoke :setup_acceptance_environment
27
- #invoke :setup_staging_environment
28
- # FUTURE autodetect rvm or rbenv
29
- invoke :configure_rvm
30
- # FUTURE invoke :configure_rbenv
31
- invoke :customize_gemfile
32
- invoke :setup_database
33
- invoke :setup_generators
34
- invoke :create_raygun_views
35
- invoke :configure_app
36
- invoke :setup_javascripts
37
- invoke :setup_stylesheets
38
- invoke :copy_miscellaneous_files
39
-
40
- # Go back to the original rvm environment.
41
- @@env.use!(rvm_original_env)
23
+
24
+ with_ruby_version do
25
+ invoke :remove_files_we_dont_need
26
+ invoke :remove_routes_comment_lines
27
+ invoke :setup_development_environment
28
+ invoke :setup_production_environment
29
+ invoke :setup_acceptance_environment
30
+ #invoke :setup_staging_environment
31
+ invoke :configure_ruby_version
32
+ invoke :customize_gemfile
33
+ invoke :setup_database
34
+ invoke :setup_generators
35
+ invoke :create_raygun_views
36
+ invoke :configure_app
37
+ invoke :setup_javascripts
38
+ invoke :setup_stylesheets
39
+ invoke :copy_miscellaneous_files
40
+ end
42
41
 
43
42
  invoke :knits_and_picks
44
43
  invoke :outro
@@ -71,15 +70,14 @@ module Raygun
71
70
  build :initialize_on_precompile
72
71
  end
73
72
 
74
- def configure_rvm
75
- say "Configuring RVM"
76
-
77
- @@env = RVM::Environment.new
78
-
79
- @@env.gemset_create(app_name)
80
- @@env.gemset_use!(app_name)
81
-
82
- build :configure_rvm
73
+ def configure_ruby_version
74
+ if rvm_installed?
75
+ say "Configuring RVM"
76
+ build :configure_rvm
77
+ else
78
+ say "Configuring rbenv"
79
+ build :configure_rbenv
80
+ end
83
81
  end
84
82
 
85
83
  def customize_gemfile
@@ -115,14 +113,17 @@ module Raygun
115
113
  build :generate_rspec
116
114
  build :add_rspec_support
117
115
 
116
+ build :add_js_testing
117
+
118
+ build :setup_logging
118
119
  build :configure_time_zone
119
120
  build :configure_action_mailer
120
121
  build :add_lib_to_load_path
121
- build :add_email_validator
122
122
  build :setup_simple_form
123
123
  build :setup_authentication
124
+ build :setup_authorization
124
125
  build :setup_default_rake_task
125
- #build :setup_guard
126
+ build :setup_guard
126
127
  end
127
128
 
128
129
  def setup_stylesheets
@@ -138,6 +139,7 @@ module Raygun
138
139
  def copy_miscellaneous_files
139
140
  say 'Copying miscellaneous support files'
140
141
  build :copy_rake_tasks
142
+ build :copy_procfile
141
143
  end
142
144
 
143
145
  def knits_and_picks
@@ -150,17 +152,16 @@ module Raygun
150
152
  say ""
151
153
  say "You're done! Next steps..."
152
154
  say ""
153
- say "# Prepare the database"
154
- say " $ cd #{ARGV[0]}"
155
- say " $ rake db:create db:migrate db:test:prepare"
155
+ say "# Prepare the database: schema and reference / sample data"
156
+ say "$ cd #{ARGV[0]}"
157
+ say "$ rake db:migrate db:seed db:sample_data"
156
158
  say ""
157
159
  say "# Run the specs (they should all pass)"
158
- say " $ rake spec"
160
+ say "$ rake"
159
161
  say ""
160
162
  say "# Load reference and sample data, then run the app and check things out"
161
- say " $ rake db:seed db:sample_data"
162
- say " $ rails s"
163
- say " $ open http://0.0.0.0:3000"
163
+ say "$ foreman start"
164
+ say "$ open http://0.0.0.0:3000"
164
165
  say ""
165
166
  say "Enjoy your Carbon Five flavored Rails application!"
166
167
  end
@@ -169,10 +170,6 @@ module Raygun
169
170
  # Let's not: We'll bundle manually at the right spot
170
171
  end
171
172
 
172
- def rvm_ruby
173
- @@env.expanded_name.match(/(.*)@?/)[1]
174
- end
175
-
176
173
  protected
177
174
 
178
175
  def get_builder_class
@@ -0,0 +1,52 @@
1
+ begin
2
+ require 'rvm'
3
+ rescue LoadError; end
4
+
5
+ module Raygun
6
+ module RubyVersionHelpers
7
+
8
+ # Executes the block within the configured ruby version manager. For rvm,
9
+ # this means that any processing in the block will happen in a new gemset
10
+ # context.
11
+ def with_ruby_version(&block)
12
+ setup_rvm if rvm_installed?
13
+ yield if block_given?
14
+ ensure
15
+ reset_rvm if rvm_installed?
16
+ end
17
+
18
+ # Records the original rvm environment and sets up a new gemset.
19
+ def setup_rvm
20
+ @@rvm_original_env ||= RVM.current.expanded_name
21
+
22
+ @@env = RVM::Environment.current
23
+ @@env.gemset_create(app_name)
24
+ @@env.gemset_use!(app_name)
25
+ end
26
+
27
+ # Reverts to the original rvm environment
28
+ def reset_rvm
29
+ @@env.use!(@@rvm_original_env)
30
+ end
31
+
32
+ # Returns the rbenv ruby version
33
+ def rbenv_ruby
34
+ `rbenv version`.split(' ').first
35
+ end
36
+
37
+ # Returns the RVM ruby version
38
+ def rvm_ruby
39
+ @@env.expanded_name.match(/(.*)@?/)[1]
40
+ end
41
+
42
+ # Returns true if rbenv is installed.
43
+ def rbenv_installed?
44
+ @rbenv_installed ||= `which rbenv`.present?
45
+ end
46
+
47
+ # Returns true if RVM is installed.
48
+ def rvm_installed?
49
+ @rvm_installed ||= `which rvm`.present?
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ [
5
+ 'helpers/ruby_version_helpers',
6
+ 'actions',
7
+ 'app_builder',
8
+ 'generators/app_generator'
9
+ ].each do |lib_path|
10
+ require File.expand_path(lib_path, File.dirname(__FILE__))
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,8 +5,10 @@ gem 'rails', '~> 3.2.8'
5
5
  gem 'slim-rails'
6
6
  gem 'jquery-rails'
7
7
  gem 'sorcery'
8
+ gem 'cancan'
8
9
  gem 'simple_form'
9
10
  gem 'active_attr'
11
+ gem 'valid_email'
10
12
  gem 'pg'
11
13
  gem 'awesome_print'
12
14
 
@@ -22,11 +24,16 @@ group :test, :development do
22
24
  gem 'rspec-rails'
23
25
  gem 'capybara', github: 'jnicklas/capybara' # TODO Change when 2.0 is released.
24
26
  gem 'factory_girl_rails'
27
+ gem 'jasminerice'
25
28
  gem 'timecop'
29
+ #gem 'simplecov'
26
30
  end
27
31
 
28
32
  group :development do
33
+ gem 'foreman'
29
34
  gem 'guard'
30
35
  gem 'guard-rspec'
36
+ gem 'guard-jasmine'
31
37
  gem 'guard-livereload'
38
+ gem 'rb-fsevent'
32
39
  end
@@ -0,0 +1,18 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
15
+
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*(\.slim)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
@@ -0,0 +1 @@
1
+ web: rails server -p 3000
@@ -7,7 +7,7 @@ Requirements
7
7
  ============
8
8
 
9
9
  * ruby 1.9.?
10
- * postgresql 9.?
10
+ * postgresql 9.? (user 'postgres' with no password)
11
11
 
12
12
  Running the Specs
13
13
  =================
@@ -18,12 +18,12 @@ $ rake
18
18
  Running the Application
19
19
  =======================
20
20
 
21
- $ rails s
21
+ $ foreman start
22
22
 
23
23
  Using Guard
24
24
  ===========
25
25
 
26
- $ guard -c
26
+ $ bundle exec guard -c
27
27
 
28
28
  Considerations
29
29
  ==============
@@ -1,6 +1,7 @@
1
1
  class UserSessionsController < ApplicationController
2
2
 
3
3
  skip_before_filter :require_login, except: [:destroy]
4
+ skip_authorization_check
4
5
 
5
6
  def new
6
7
  @user_session = UserSession.new
@@ -0,0 +1,36 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ user ||= User.new # guest user (not logged in)
6
+
7
+ if user.admin?
8
+ can :manage, User
9
+ else
10
+ can :manage, User, id: user.id
11
+ end
12
+
13
+ # Define abilities for the passed in user here. For example:
14
+ #
15
+ # user ||= User.new # guest user (not logged in)
16
+ # if user.admin?
17
+ # can :manage, :all
18
+ # else
19
+ # can :read, :all
20
+ # end
21
+ #
22
+ # The first argument to `can` is the action you are giving the user permission to do.
23
+ # If you pass :manage it will apply to every action. Other common actions here are
24
+ # :read, :create, :update and :destroy.
25
+ #
26
+ # The second argument is the resource the user can perform the action on. If you pass
27
+ # :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
28
+ #
29
+ # The third argument is an optional hash of conditions to further filter the objects.
30
+ # For example, here the user can only update published articles.
31
+ #
32
+ # can :update, Article, :published => true
33
+ #
34
+ # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
35
+ end
36
+ end
@@ -10,7 +10,7 @@ class User < ActiveRecord::Base
10
10
 
11
11
  validates :password,
12
12
  presence: true,
13
- length: { minimum: 3},
13
+ length: { minimum: 6 },
14
14
  confirmation: true,
15
15
  if: :password
16
16
 
@@ -12,6 +12,13 @@
12
12
 
13
13
  User.create! do |u|
14
14
  u.email = 'user@example.com'
15
- u.name = 'John Smith'
15
+ u.name = 'Ustead User'
16
16
  u.password = 'password'
17
17
  end.activate!
18
+
19
+ User.create! do |u|
20
+ u.email = 'admin@example.com'
21
+ u.name = 'Adam Admin'
22
+ u.password = 'password'
23
+ u.admin = true
24
+ end.activate!
@@ -0,0 +1,12 @@
1
+ namespace :spec do
2
+ task :enable_coverage do
3
+ ENV['COVERAGE'] = '1'
4
+ end
5
+
6
+ desc 'Executes specs with code coverage reports'
7
+ task coverage: :enable_coverage do
8
+ Rake::Task[:spec].invoke
9
+ end
10
+ end
11
+
12
+ Rake::Task['spec'].enhance ['spec:enable_coverage']
@@ -1,6 +1,6 @@
1
1
  namespace :db do
2
2
  desc "Load a small, representative set of data so that the application can start in an use state (for development)."
3
- task :sample_data => :environment do
3
+ task sample_data: :environment do
4
4
  sample_data = File.join(Rails.root, 'db', 'sample_data.rb')
5
5
  load(sample_data) if sample_data
6
6
  end
@@ -0,0 +1,18 @@
1
+ require 'guard/jasmine/task'
2
+
3
+ namespace :spec do
4
+ desc "Run all javascript specs"
5
+ task :javascripts do
6
+ begin
7
+ ::Guard::Jasmine::CLI.start
8
+
9
+ rescue SystemExit => e
10
+ case e.status
11
+ when 1
12
+ fail "Some specs have failed"
13
+ when 2
14
+ fail "The spec couldn't be run: #{e.message}'"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+
8
+ load_and_authorize_resource
9
+
10
+ def index
11
+ end
12
+
13
+ def show
14
+ end
15
+
16
+ def new
17
+ end
18
+
19
+ def edit
20
+ end
21
+
22
+ def create
23
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
24
+
25
+ if @<%= orm_instance.save %>
26
+ redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully created.'" %>
27
+ else
28
+ render <%= key_value :action, '"new"' %>
29
+ end
30
+ end
31
+
32
+ def update
33
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
34
+ redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully updated.'" %>
35
+ else
36
+ render <%= key_value :action, '"edit"' %>
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ @<%= orm_instance.destroy %>
42
+ redirect_to <%= index_helper %>_url
43
+ end
44
+ end
45
+ <% end -%>
@@ -3,7 +3,7 @@
3
3
 
4
4
  .form-inputs
5
5
  <%- attributes.each_with_index do |attribute, i| -%>
6
- = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> <%= ", autofocus:true" if i == 0 %>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %><%= ', autofocus: true' if i == 0 %>
7
7
  <%- end -%>
8
8
 
9
9
  .form-actions
@@ -13,15 +13,16 @@ table.table.table-striped
13
13
  tbody
14
14
  - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
15
15
  tr
16
- td= link_to <%= singular_table_name %>.id, <%= singular_table_name %>_path(<%= singular_table_name %>)
16
+ td= link_to_if can?(:show, <%= singular_table_name %>), <%= singular_table_name %>.id, <%= singular_table_name %>_path(<%= singular_table_name %>)
17
17
  <% attributes.each do |attribute| -%>
18
18
  td= <%= singular_table_name %>.<%= attribute.name %>
19
19
  <% end -%>
20
20
  td
21
- = link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'btn btn-mini'
22
- '
23
- = link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure?" }, class: 'btn btn-mini btn-danger'
21
+ - if can? :edit, <%= singular_table_name %>
22
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'btn btn-mini'
23
+ '
24
+ - if can? :destroy, <%= singular_table_name %>
25
+ = link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure?" }, class: 'btn btn-mini btn-danger'
24
26
 
25
- br
26
-
27
- = link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path, class: 'btn btn-primary'
27
+ - if can? :create, <%= singular_table_name.classify %>
28
+ = link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path, class: 'btn btn-primary'
@@ -1,15 +1,17 @@
1
1
  .page-header
2
- h1 <%= singular_table_name %>
2
+ h1 <%= singular_table_name.capitalize %>
3
3
 
4
+ dl
4
5
  <% attributes.each do |attribute| -%>
5
- p
6
- strong <%= attribute.human_name %>:
7
- = @<%= singular_table_name %>.<%= attribute.name %>
6
+ dt <%= attribute.human_name %>
7
+ dd= @<%= singular_table_name %>.<%= attribute.name %>
8
8
  <% end -%>
9
9
 
10
- = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'btn'
11
- '
10
+ - if can?(:edit, @<%= singular_table_name %>)
11
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'btn'
12
+ '
12
13
  = link_to 'Back', <%= index_helper %>_path, class: 'btn'
13
- '
14
- = link_to 'Destroy', <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure?" }, class: 'btn btn-danger'
15
14
 
15
+ - if can?(:destroy, @<%= singular_table_name %>)
16
+ '
17
+ = link_to'Destroy', <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure?" }, class: 'btn btn-danger'
@@ -3,5 +3,10 @@ FactoryGirl.define do
3
3
  sequence(:email) { |n| "person#{n}@example.com" }
4
4
  name 'Tom Middleton'
5
5
  password 'password'
6
+
7
+ factory :admin do
8
+ name 'Admin'
9
+ admin true
10
+ end
6
11
  end
7
12
  end
@@ -0,0 +1,20 @@
1
+ # This is an example spec, delete when there are some real specs.
2
+
3
+ class Foo
4
+ bar: ->
5
+ false
6
+
7
+ class Bar
8
+ foo: ->
9
+ false
10
+
11
+
12
+ describe "Foo", ->
13
+ it "it is not bar", ->
14
+ v = new Foo()
15
+ expect(v.bar()).toEqual(false)
16
+
17
+ describe "Bar", ->
18
+ it "it is not foo", ->
19
+ v = new Bar()
20
+ expect(v.foo()).toEqual(false)
@@ -0,0 +1,3 @@
1
+ /*
2
+ *=require application
3
+ */
@@ -0,0 +1,2 @@
1
+ #=require application
2
+ #=require_tree ./
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'cancan/matchers'
3
+
4
+ describe "User" do
5
+ context "when working with User" do
6
+ context "as a non-admin" do
7
+ let(:user) { build(:user) { |u| u.id = 1 } }
8
+ subject { Ability.new(user) }
9
+
10
+ context "operating on themselves" do
11
+ it { should be_able_to(:manage, user) }
12
+ end
13
+
14
+ context "operating on someone else" do
15
+ let(:other) { build(:user) { |u| u.id = 2 } }
16
+
17
+ it { should_not be_able_to(:manage, other) }
18
+ end
19
+ end
20
+
21
+ context "as an admin" do
22
+ let(:user) { build(:admin) { |u| u.id = 1 } }
23
+ subject { Ability.new(user) }
24
+
25
+ context "operating on themselves" do
26
+ it { should be_able_to(:manage, user) }
27
+ end
28
+
29
+ context "operating on someone else" do
30
+ let(:other) { build(:user) { |u| u.id = 2 } }
31
+
32
+ it { should be_able_to(:manage, other) }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ <%= rbenv_ruby %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2012-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -84,6 +84,7 @@ extensions: []
84
84
  extra_rdoc_files: []
85
85
  files:
86
86
  - .gitignore
87
+ - .rbenv-version
87
88
  - .rvmrc
88
89
  - Gemfile
89
90
  - LICENSE.txt
@@ -91,13 +92,22 @@ files:
91
92
  - Rakefile
92
93
  - TODO.md
93
94
  - bin/raygun
95
+ - generators/application_template.rb
96
+ - generators/simplecov/simplecov.rb
97
+ - generators/simplecov/simplecov_template.rb
98
+ - generators/simplecov/spec/support/simplecov.rb
99
+ - generators/simplecov/tasks/coverage.rake
94
100
  - lib/raygun/actions.rb
95
101
  - lib/raygun/app_builder.rb
96
102
  - lib/raygun/generators/app_generator.rb
103
+ - lib/raygun/helpers/ruby_version_helpers.rb
104
+ - lib/raygun/raygun.rb
97
105
  - lib/raygun/version.rb
98
106
  - marvin.jpg
99
107
  - raygun.gemspec
100
108
  - templates/Gemfile_customized
109
+ - templates/Guardfile_customized
110
+ - templates/Procfile
101
111
  - templates/README.md.erb
102
112
  - templates/_app/assets/stylesheets/_footer.less
103
113
  - templates/_app/assets/stylesheets/application.css.less
@@ -107,6 +117,7 @@ files:
107
117
  - templates/_app/controllers/user_sessions_controller.rb
108
118
  - templates/_app/helpers/application_helper.rb
109
119
  - templates/_app/mailers/user_mailer.rb
120
+ - templates/_app/models/ability.rb
110
121
  - templates/_app/models/user.rb
111
122
  - templates/_app/models/user_session.rb
112
123
  - templates/_app/views/layouts/application.html.slim.erb
@@ -122,8 +133,10 @@ files:
122
133
  - templates/_app/views/user_sessions/new.html.slim
123
134
  - templates/_config/database.yml.erb
124
135
  - templates/_db/sample_data.rb
125
- - templates/_lib/email_validator.rb
136
+ - templates/_lib/tasks/coverage.rake
126
137
  - templates/_lib/tasks/db.rake
138
+ - templates/_lib/tasks/spec.rake
139
+ - templates/_lib/templates/rails/scaffold_controller/controller.rb
127
140
  - templates/_lib/templates/rspec/scaffold/controller_spec.rb
128
141
  - templates/_lib/templates/slim/scaffold/_form.html.slim
129
142
  - templates/_lib/templates/slim/scaffold/edit.html.slim
@@ -132,13 +145,18 @@ files:
132
145
  - templates/_lib/templates/slim/scaffold/show.html.slim
133
146
  - templates/_public/index.html.erb
134
147
  - templates/_spec/factories/users.rb
148
+ - templates/_spec/javascripts/example_spec.js.coffee
149
+ - templates/_spec/javascripts/spec.css
150
+ - templates/_spec/javascripts/spec.js.coffee
135
151
  - templates/_spec/mailers/user_mailer_spec.rb
152
+ - templates/_spec/models/ability_spec.rb
136
153
  - templates/_spec/models/user_spec.rb
137
154
  - templates/_spec/requests/user_sessions_spec.rb
138
155
  - templates/_spec/support/accept_values.rb
139
156
  - templates/_spec/support/factory_girl.rb
140
157
  - templates/_spec/support/sorcery.rb
141
158
  - templates/_spec/support/user_sessions_request_helper.rb
159
+ - templates/rbenv-version.erb
142
160
  - templates/rvmrc.erb
143
161
  homepage: https://github.com/carbonfive/raygun
144
162
  licenses: []
@@ -1,9 +0,0 @@
1
- class EmailValidator < ActiveModel::EachValidator
2
-
3
- def validate_each(record, attribute, value)
4
- unless value =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
5
- record.errors[attribute] << (options[:message] || "is not an email")
6
- end
7
- end
8
-
9
- end