jakewendt-photos 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/README.rdoc +59 -0
  2. data/app/controllers/photos_controller.rb +46 -0
  3. data/app/models/photo.rb +11 -0
  4. data/app/views/photos/_form.html.erb +16 -0
  5. data/app/views/photos/_photo.html.erb +12 -0
  6. data/app/views/photos/edit.html.erb +4 -0
  7. data/app/views/photos/index.html.erb +9 -0
  8. data/app/views/photos/new.html.erb +3 -0
  9. data/app/views/photos/show.html.erb +24 -0
  10. data/config/photo.yml +59 -0
  11. data/config/routes.rb +14 -0
  12. data/generators/photos/USAGE +0 -0
  13. data/generators/photos/photos_generator.rb +77 -0
  14. data/generators/photos/templates/functional/photos_controller_test.rb +64 -0
  15. data/generators/photos/templates/images/full/missing.png +0 -0
  16. data/generators/photos/templates/images/large/missing.png +0 -0
  17. data/generators/photos/templates/images/medium/missing.png +0 -0
  18. data/generators/photos/templates/images/original/missing.png +0 -0
  19. data/generators/photos/templates/images/small/missing.png +0 -0
  20. data/generators/photos/templates/migrations/add_attachments_image_to_photo.rb +15 -0
  21. data/generators/photos/templates/migrations/create_photos.rb +13 -0
  22. data/generators/photos/templates/unit/photo_test.rb +24 -0
  23. data/lib/photos.rb +56 -0
  24. data/lib/photos/factories.rb +19 -0
  25. data/lib/photos/factory_test_helper.rb +47 -0
  26. data/lib/photos/file_utils_extension.rb +18 -0
  27. data/lib/photos/pending.rb +72 -0
  28. data/lib/photos/tasks.rb +1 -0
  29. data/lib/tasks/application.rake +40 -0
  30. data/lib/tasks/database.rake +52 -0
  31. data/lib/tasks/documentation.rake +68 -0
  32. data/lib/tasks/rcov.rake +41 -0
  33. data/lib/tasks/ucb_ccls_engine_tasks.rake +50 -0
  34. metadata +212 -0
@@ -0,0 +1,59 @@
1
+ = Photos
2
+
3
+ i18n-0.4.1 is really p!$$!ng me off.
4
+ It's simple existance reaks havoc.
5
+
6
+ == ToDo
7
+
8
+ * Add tabbed view of photos styles
9
+ * Add image link to view to easy copy/pasting
10
+
11
+ == Required Gem Sources
12
+
13
+ gem sources -a http://rubygems.org
14
+ gem sources -a http://gems.github.com
15
+
16
+ == Required Gems
17
+
18
+ * {ruby_extension}[http://github.com/jakewendt/ruby_extension] - modifications, updates and patches for ruby.
19
+ * {assert_this_and_that}[http://github.com/jakewendt/assert_this_and_that]
20
+ * rails ~> 2
21
+ * i18n =0.3.7
22
+ * ssl_requirement
23
+ * ryanb-acts-as-list
24
+ * RedCloth
25
+ * paperclip
26
+ * thoughtbot-factory_girl
27
+ * jakewendt-rails_helpers
28
+ * jakewendt-ruby_extension
29
+ * jakewendt-calnet_authenticated
30
+ * jakewendt-authorized
31
+
32
+ == Installation (as a plugin/engine)
33
+
34
+ cp config/s3.yml.example config/s3.yml
35
+ # Add your own s3 access keys. Leave 'test' as it is.
36
+
37
+ == Testing (as an app)
38
+
39
+ rake db:migrate
40
+ rake db:fixtures:load
41
+ rake test
42
+ script/server
43
+
44
+ == Gemified with Jeweler
45
+
46
+ vi Rakefile
47
+ rake version:write
48
+
49
+ rake version:bump:patch
50
+ rake version:bump:minor
51
+ rake version:bump:major
52
+
53
+ rake gemspec
54
+
55
+ rake install
56
+ rake release
57
+
58
+
59
+ Copyright (c) 2010 [Jake Wendt], released under the MIT license
@@ -0,0 +1,46 @@
1
+ class PhotosController < ApplicationController
2
+
3
+ before_filter :may_maintain_pages_required
4
+ before_filter :id_required, :only => [ :show, :edit, :update, :destroy ]
5
+
6
+ def index
7
+ @photos = Photo.all
8
+ end
9
+
10
+ def new
11
+ @photo = Photo.new
12
+ end
13
+
14
+ def create
15
+ @photo = Photo.new(params[:photo])
16
+ @photo.save!
17
+ redirect_to @photo
18
+ rescue ActiveRecord::RecordInvalid
19
+ flash.now[:error] = "Error"
20
+ render :action => 'new'
21
+ end
22
+
23
+ def update
24
+ @photo.update_attributes!(params[:photo])
25
+ redirect_to @photo
26
+ rescue ActiveRecord::RecordInvalid
27
+ flash.now[:error] = "Error"
28
+ render :action => 'edit'
29
+ end
30
+
31
+ def destroy
32
+ @photo.destroy
33
+ redirect_to photos_path
34
+ end
35
+
36
+ protected
37
+
38
+ def id_required
39
+ if !params[:id].blank? and Photo.exists?(params[:id])
40
+ @photo = Photo.find(params[:id])
41
+ else
42
+ access_denied("Valid photo id required!", photos_path)
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,11 @@
1
+ class Photo < ActiveRecord::Base
2
+
3
+ validates_presence_of :title
4
+ validates_length_of :title, :minimum => 4
5
+
6
+ has_attached_file :image,
7
+ YAML::load(ERB.new(IO.read(File.expand_path(
8
+ File.join(File.dirname(__FILE__),'../..','config/photo.yml')
9
+ ))).result)[Rails.env]
10
+
11
+ end
@@ -0,0 +1,16 @@
1
+ <%# stylesheets('photo') %>
2
+
3
+ <% form_for(@photo,:html => { :multipart => true }) do |f| %>
4
+ <%= f.error_messages %>
5
+ <%= f.wrapped_text_field :title %>
6
+ <%= f.wrapped_file_field :image %>
7
+ <% if @photo.image? %>
8
+ <div class='image_preview'>
9
+ <%= image_tag(@photo.image.url(:full))%>
10
+ </div>
11
+ <% end %>
12
+ <%= f.wrapped_text_area :caption %>
13
+ <p>
14
+ <%= f.submit( (@photo.new_record?)? "Create" : "Update" )%>
15
+ </p>
16
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% content_tag_for( :tr, photo, :class => 'row' ) do %>
2
+ <td class='thumb'>
3
+ <%= image_tag(photo.image.url(:small)) %>
4
+ </td>
5
+ <td class='title'>
6
+ <%= link_to photo.title, photo %>
7
+ </td>
8
+ <td class='manage'>
9
+ <%= button_link_to 'Edit', edit_photo_path(photo) %>&nbsp;
10
+ <%= destroy_link_to 'Destroy', photo_path(photo) %>
11
+ </td>
12
+ <% end %><!-- class='photo row' -->
@@ -0,0 +1,4 @@
1
+ <h1>Editing Photo</h1>
2
+ <%= render 'form' %>
3
+ <%= link_to 'Show', @photo %> |
4
+ <%= link_to 'Back', photos_path %>
@@ -0,0 +1,9 @@
1
+ <% stylesheets('photos') %>
2
+
3
+ <% if @photos.length > 0 %>
4
+ <table id='photos'><tbody>
5
+ <%= render :partial => 'photo', :collection => @photos %>
6
+ </tbody></table><!-- id='photos' -->
7
+ <% end %>
8
+
9
+ <p><%= link_to 'Create New Photo', new_photo_path %></p>
@@ -0,0 +1,3 @@
1
+ <h1>New Photo</h1>
2
+ <%= render 'form' %>
3
+ <%= link_to 'Back', photos_path %>
@@ -0,0 +1,24 @@
1
+ <%# stylesheets('photo') %>
2
+
3
+ <p>
4
+ <b>Title:</b>
5
+ <%=h @photo.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Image:</b>
10
+ </p>
11
+ <% @photo.image.styles.keys.unshift(:original).each do |key| %>
12
+ <div class='image_preview'>
13
+ <p><%= link_to( @photo.image.url(key), @photo.image.url(key) ) %></p>
14
+ <%= image_tag @photo.image.url(key) %>
15
+ </div>
16
+ <% end %>
17
+
18
+ <p>
19
+ <b>Caption:</b>
20
+ <%=h @photo.caption %>
21
+ </p>
22
+
23
+ <%= link_to 'Edit', edit_photo_path(@photo) %> |
24
+ <%= link_to 'Back', photos_path %>
@@ -0,0 +1,59 @@
1
+ DEFAULTS: &DEFAULTS
2
+ :styles:
3
+ :full: '900>'
4
+ :large: '800>'
5
+ :medium: '600>'
6
+ :small: '150x50>'
7
+
8
+ # > means DO NOT enlarge, only shrink
9
+
10
+ # :attachment is the attachment name NOT the model name
11
+ # for document they are the same, but not photos
12
+
13
+ # why /system/ ???
14
+ <%# common = "/system/:attachment/:id/:style/:filename" %>
15
+ <% common = "photos/:id/:style/:filename" %>
16
+
17
+
18
+ #>> Rails.root.to_s.split('/')
19
+ #=> ["", "var", "lib", "tomcat5", "webapps", "clic", "WEB-INF"]
20
+
21
+ #>> Rails.root.to_s.split('/')
22
+ #=> ["", "Users", "jakewendt", "github_repo", "jakewendt", "ucb_ccls_clic"]
23
+
24
+ <%
25
+ app_name = ( defined?(RAILS_APP_NAME) ) ?
26
+ RAILS_APP_NAME :
27
+ Rails.root.to_s.split('/').reject{|x|x == "WEB-INF"}.last
28
+ %>
29
+
30
+
31
+ development:
32
+ :url: <%= "/development/#{common}" %>
33
+ :path: <%= "#{Rails.root}/public/development/#{common}" %>
34
+ <<: *DEFAULTS
35
+
36
+ test:
37
+ :url: <%= "/test/#{common}" %>
38
+ :path: <%= "#{Rails.root}/public/test/#{common}" %>
39
+ <<: *DEFAULTS
40
+
41
+ production:
42
+ # Set the storage class to RRS which is cheaper than
43
+ # the default of STANDARD
44
+ :s3_headers:
45
+ x-amz-storage-class: REDUCED_REDUNDANCY
46
+ # public_read or private
47
+ :s3_permissions: :public_read
48
+ :storage: :s3
49
+ :s3_protocol: https
50
+ :s3_credentials: <%="#{Rails.root}/config/s3.yml" %>
51
+ :bucket: <%= app_name %>
52
+ # common has a : as the first char so it needs special care
53
+ # or the string will magically be turned into a symbol
54
+ # which isn't what we want <%#= "\"#{common}\"" %>
55
+ # Not anymore.
56
+ :path: <%= common %>
57
+ # S3 must have a defined path or will generate
58
+ # "Stack level too deep" errors
59
+ <<: *DEFAULTS
@@ -0,0 +1,14 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ # http://wiki.rubyonrails.org/rails/pages/ReservedWords
4
+ # image - Due to that there is an image_path helper, using images as a restful route will cause issues.
5
+ # test_AWiHTTPS_should_get_index_with_admin_login(DocumentsControllerTest):
6
+ # ActionView::TemplateError: image_url failed to generate
7
+ # from {:controller=>"images", :action=>"show", :id=>"cal.ico"},
8
+ # expected: {:controller=>"images", :action=>"show"}, diff: {:id=>"cal.ico"}
9
+ # On line #6 of app/views/layouts/application.html.erb
10
+ # map.resources :images
11
+
12
+ map.resources :photos
13
+
14
+ end
File without changes
@@ -0,0 +1,77 @@
1
+ class PhotosGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ # See Rails::Generator::Commands::Create
5
+ # rails-2.3.10/lib/rails_generator/commands.rb
6
+ # for code methods for record (Manifest)
7
+ record do |m|
8
+
9
+ %w( create_photos add_attachments_image_to_photo
10
+ ).each do |migration|
11
+ m.migration_template "migrations/#{migration}.rb",
12
+ 'db/migrate', :migration_file_name => migration
13
+ end
14
+ dot = File.dirname(__FILE__)
15
+ m.directory('public/javascripts')
16
+ Dir["#{dot}/templates/javascripts/*js"].each{|file|
17
+ f = file.split('/').slice(-2,2).join('/')
18
+ m.file(f, "public/javascripts/#{File.basename(file)}")
19
+ }
20
+ m.directory('public/stylesheets')
21
+ Dir["#{dot}/templates/stylesheets/*css"].each{|file|
22
+ f = file.split('/').slice(-2,2).join('/')
23
+ m.file(f, "public/stylesheets/#{File.basename(file)}")
24
+ }
25
+
26
+
27
+ m.directory('public/images')
28
+ %w( full large medium original small ).each do |style|
29
+ m.directory("public/images/#{style}")
30
+ m.file("images/#{style}/missing.png",
31
+ "public/images/#{style}/missing.png")
32
+ end
33
+
34
+
35
+ m.directory('test/functional/photos')
36
+ Dir["#{dot}/templates/functional/*rb"].each{|file|
37
+ f = file.split('/').slice(-2,2).join('/')
38
+ m.file(f, "test/functional/photos/#{File.basename(file)}")
39
+ }
40
+ m.directory('test/unit/photos')
41
+ Dir["#{dot}/templates/unit/*rb"].each{|file|
42
+ f = file.split('/').slice(-2,2).join('/')
43
+ m.file(f, "test/unit/photos/#{File.basename(file)}")
44
+ }
45
+ end
46
+ end
47
+
48
+ end
49
+ module Rails::Generator::Commands
50
+ class Create
51
+ def migration_template(relative_source,
52
+ relative_destination, template_options = {})
53
+ migration_directory relative_destination
54
+ migration_file_name = template_options[
55
+ :migration_file_name] || file_name
56
+ if migration_exists?(migration_file_name)
57
+ puts "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}: Skipping"
58
+ else
59
+ template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
60
+ end
61
+ end
62
+ end # Create
63
+ class Base
64
+ protected
65
+ # the loop through migrations happens so fast
66
+ # that they all have the same timestamp which
67
+ # won't work when you actually try to migrate.
68
+ # All the timestamps MUST be unique.
69
+ def next_migration_string(padding = 3)
70
+ @s = (!@s.nil?)? @s.to_i + 1 : if ActiveRecord::Base.timestamped_migrations
71
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
72
+ else
73
+ "%.#{padding}d" % next_migration_number
74
+ end
75
+ end
76
+ end # Base
77
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class Photos::PhotosControllerTest < ActionController::TestCase
4
+ tests PhotosController
5
+
6
+ ASSERT_ACCESS_OPTIONS = {
7
+ :model => 'Photo',
8
+ :actions => [:new,:create,:edit,:update,:destroy,:show,:index],
9
+ :method_for_create => :factory_create,
10
+ :attributes_for_create => :factory_attributes
11
+ }
12
+
13
+ def factory_create(options={})
14
+ Factory(:photo,options)
15
+ end
16
+ def factory_attributes(options={})
17
+ Factory.attributes_for(:photo,options)
18
+ end
19
+
20
+ assert_access_with_https
21
+ assert_access_with_login({
22
+ :logins => [:super_user,:admin,:editor]})
23
+
24
+ assert_no_access_with_http
25
+ assert_no_access_with_login({
26
+ :logins => [:interviewer,:reader,:active_user] })
27
+ assert_no_access_without_login
28
+
29
+ assert_no_access_with_login(
30
+ :attributes_for_create => nil,
31
+ :method_for_create => nil,
32
+ :actions => nil,
33
+ :suffix => " and invalid id",
34
+ :login => :super_user,
35
+ :redirect => :photos_path,
36
+ :edit => { :id => 0 },
37
+ :update => { :id => 0 },
38
+ :destroy => { :id => 0 }
39
+ )
40
+
41
+ %w( super_user admin editor ).each do |cu|
42
+
43
+ test "should NOT create invalid photo with #{cu} login" do
44
+ login_as send(cu)
45
+ assert_no_difference('Photo.count') do
46
+ post :create, :photo => {}
47
+ end
48
+ assert_not_nil flash[:error]
49
+ assert_template 'new'
50
+ assert_response :success
51
+ end
52
+
53
+ test "should NOT update invalid photo with #{cu} login" do
54
+ login_as send(cu)
55
+ put :update, :id => factory_create.id,
56
+ :photo => { :title => "a" }
57
+ assert_not_nil flash[:error]
58
+ assert_template 'edit'
59
+ assert_response :success
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,15 @@
1
+ class AddAttachmentsImageToPhoto < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :photos, :image_file_name, :string
4
+ add_column :photos, :image_content_type, :string
5
+ add_column :photos, :image_file_size, :integer
6
+ add_column :photos, :image_updated_at, :datetime
7
+ end
8
+
9
+ def self.down
10
+ remove_column :photos, :image_file_name
11
+ remove_column :photos, :image_content_type
12
+ remove_column :photos, :image_file_size
13
+ remove_column :photos, :image_updated_at
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePhotos < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :photos do |t|
4
+ t.string :title, :null => false
5
+ t.text :caption
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :photos
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class Photos::PhotoTest < ActiveSupport::TestCase
4
+
5
+ assert_should_require(:title,
6
+ :model => 'Photo')
7
+
8
+ test "should create photo" do
9
+ assert_difference 'Photo.count' do
10
+ object = create_object
11
+ assert !object.new_record?,
12
+ "#{object.errors.full_messages.to_sentence}"
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def create_object(options = {})
19
+ record = Factory.build(:photo,options)
20
+ record.save
21
+ record
22
+ end
23
+
24
+ end
@@ -0,0 +1,56 @@
1
+ # The i18n-0.4.1 gem is still wreaking havoc.
2
+ gem 'i18n', '=0.3.7'
3
+ module Photos
4
+ # predefine namespace
5
+ end
6
+ gem 'activerecord', '~> 2'
7
+ require 'active_record'
8
+ require 'action_controller'
9
+ require 'active_support'
10
+ require 'ruby_extension'
11
+ require 'rails_helpers'
12
+ require 'authorized'
13
+ require 'calnet_authenticated'
14
+ require 'acts_as_list'
15
+
16
+ HTML::WhiteListSanitizer.allowed_attributes.merge(%w(
17
+ id class style
18
+ ))
19
+
20
+ %w{models controllers}.each do |dir|
21
+ path = File.expand_path(File.join(File.dirname(__FILE__), '../app', dir))
22
+ ActiveSupport::Dependencies.autoload_paths << path
23
+ ActiveSupport::Dependencies.autoload_once_paths << path
24
+ end
25
+
26
+ if !defined?(RAILS_ENV) || RAILS_ENV == 'test'
27
+ require 'active_support/test_case'
28
+ require 'factory_girl'
29
+ require 'assert_this_and_that'
30
+ require 'photos/factories'
31
+ require 'photos/factory_test_helper'
32
+ require 'photos/pending'
33
+ end
34
+
35
+ if RUBY_PLATFORM =~ /java/i
36
+ require 'photos/file_utils_extension'
37
+ end
38
+
39
+ require 'paperclip'
40
+ if defined? ::Paperclip::Glue
41
+ ActiveRecord::Base.send(:include, ::Paperclip::Glue)
42
+ else
43
+ ActiveRecord::Base.send(:include, ::Paperclip)
44
+ end
45
+
46
+
47
+ ActionController::Routing::Routes.add_configuration_file(
48
+ File.expand_path(
49
+ File.join(
50
+ File.dirname(__FILE__), '../config/routes.rb')))
51
+
52
+ ActionController::Base.view_paths <<
53
+ File.expand_path(
54
+ File.join(
55
+ File.dirname(__FILE__), '../app/views'))
56
+
@@ -0,0 +1,19 @@
1
+ Factory.define :photo do |f|
2
+ f.sequence(:title) { |n| "Title#{n}" }
3
+ end
4
+
5
+ #Factory.define :role do |f|
6
+ # f.sequence(:name) { |n| "name#{n}" }
7
+ #end
8
+
9
+ Factory.define :user do |f|
10
+ f.sequence(:uid) { |n| "UID#{n}" }
11
+ # f.sequence(:username) { |n| "username#{n}" }
12
+ # f.sequence(:email) { |n| "username#{n}@example.com" }
13
+ # f.password 'V@1!dP@55w0rd'
14
+ # f.password_confirmation 'V@1!dP@55w0rd'
15
+ # f.role_name 'user'
16
+ end
17
+ Factory.define :admin_user, :parent => :user do |f|
18
+ f.administrator true
19
+ end # parent must be defined first
@@ -0,0 +1,47 @@
1
+ module Photos::FactoryTestHelper
2
+
3
+ def active_user(options={})
4
+ u = Factory(:user, options)
5
+ # leave this special save here just in case I change things.
6
+ # although this would need changed for UCB CAS.
7
+ # u.save_without_session_maintenance
8
+ # u
9
+ end
10
+ alias_method :user, :active_user
11
+
12
+ def superuser(options={})
13
+ u = active_user(options)
14
+ u.roles << Role.find_or_create_by_name('superuser')
15
+ u
16
+ end
17
+ alias_method :super_user, :superuser
18
+
19
+ def admin_user(options={})
20
+ u = active_user(options)
21
+ u.roles << Role.find_or_create_by_name('administrator')
22
+ u
23
+ end
24
+ alias_method :admin, :admin_user
25
+ alias_method :administrator, :admin_user
26
+
27
+ def interviewer(options={})
28
+ u = active_user(options)
29
+ u.roles << Role.find_or_create_by_name('interviewer')
30
+ u
31
+ end
32
+
33
+ def reader(options={})
34
+ u = active_user(options)
35
+ u.roles << Role.find_or_create_by_name('reader')
36
+ u
37
+ end
38
+ # alias_method :employee, :reader
39
+
40
+ def editor(options={})
41
+ u = active_user(options)
42
+ u.roles << Role.find_or_create_by_name('editor')
43
+ u
44
+ end
45
+
46
+ end
47
+ ActiveSupport::TestCase.send(:include,Photos::FactoryTestHelper)
@@ -0,0 +1,18 @@
1
+ # Needed for Paperclip gem 2.3.3
2
+ # http://jira.codehaus.org/browse/JRUBY-3381
3
+ # http://github.com/thoughtbot/paperclip/issues/issue/193
4
+ # Errno::EACCES: Permission denied - /var/folders/kV/kV5XVPtqE9uZBCjn3z6vmk+++TM/-Tmp-/stream,19661,34729.pdf or /Users/jakewendt/github_repo/jakewendt/ucb_ccls_buffler/development/documents/2/edit_save_wireframe.pdf
5
+ FileUtils.module_eval do
6
+ class << self
7
+ alias_method :built_in_mv, :mv
8
+
9
+ def mv(src, dest, options = {})
10
+ begin
11
+ built_in_mv(src, dest, options)
12
+ rescue Errno::EACCES
13
+ cp(src, dest)
14
+ rm(src)
15
+ end
16
+ end
17
+ end
18
+ end unless FileUtils.methods.include?('built_in_mv')
@@ -0,0 +1,72 @@
1
+ # Some code from jeremymcanally's "pending"
2
+ # http://github.com/jeremymcanally/pending/tree/master
3
+
4
+ module ActiveSupport
5
+ module Testing
6
+ module Pending
7
+
8
+ unless defined?(Spec)
9
+
10
+ @@pending_cases = []
11
+ @@at_exit = false
12
+
13
+ def pending(description = "", &block)
14
+ if description.is_a?(Symbol)
15
+ is_pending = $tags[description]
16
+ return block.call unless is_pending
17
+ end
18
+
19
+ if block_given?
20
+ failed = false
21
+
22
+ begin
23
+ block.call
24
+ rescue Exception
25
+ failed = true
26
+ end
27
+
28
+ flunk("<#{description}> did not fail.") unless failed
29
+ end
30
+
31
+ caller[0] =~ (/(.*):(.*):in `(.*)'/)
32
+ #puts caller.inspect
33
+
34
+ # looks like we lose the name of the 'method' in 1.9.1
35
+ #"/Users/jakewendt/github_repo/jakewendt/ucb_ccls_homex/test/unit/subject_test.rb:145:in `block in <class:SubjectTest>'",
36
+
37
+ # @@pending_cases << "#{$3} at #{$1}, line #{$2}"
38
+ # Gotta remember these as the next Regex will overwrite them.
39
+ filename = $1
40
+ linenumber = $2
41
+ # ruby 1.8.7
42
+ # Hx/Addresses Controller should NOT create new address with employee login and invalid address:
43
+ # ruby 1.9.1
44
+ #Hx/Addresses Controller block (2 levels) in <class:AddressesControllerTest>:
45
+ testmethod = $3
46
+
47
+ model = self.class.to_s.gsub(/Test$/,'').titleize
48
+ method = testmethod.gsub(/_/,' ').gsub(/^test /,'')
49
+ @@pending_cases << "#{model} #{method}:\n.\t#{filename} line #{linenumber}"
50
+ # @@pending_cases << "#{testmethod} at #{filename}, line #{linenumber}"
51
+ print "P"
52
+
53
+ @@at_exit ||= begin
54
+ at_exit do
55
+ # For some reason, special characters don't always
56
+ # print the way you would expect. Leading white space (tabs)
57
+ # and some carriage returns just weren't happening?
58
+ # Is this at_exit doing some parsing??
59
+ puts "\nPending Cases:"
60
+ @@pending_cases.each do |test_case|
61
+ puts test_case
62
+ end
63
+ puts " \n"
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ ActiveSupport::TestCase.send(:include, ActiveSupport::Testing::Pending)
@@ -0,0 +1 @@
1
+ Dir["#{File.dirname(__FILE__)}/../tasks/**/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,40 @@
1
+ namespace :app do
2
+
3
+ # task :args_as_array do
4
+ # args = $*.dup.slice(1..-1)
5
+ # puts args.collect {|arg| "X:" << arg }.join("\n")
6
+ # exit
7
+ # end
8
+
9
+ desc "Add some expected users."
10
+ task :add_users => :environment do
11
+ puts "Adding users"
12
+ %w( 859908 228181 855747 214766 180918 66458 808 768475
13
+ 10883 86094 754783 769067 854720 16647 ).each do |uid|
14
+ puts " - Adding user with uid:#{uid}:"
15
+ User.find_create_and_update_by_uid(uid)
16
+ end
17
+ end
18
+
19
+ desc "Deputize user by UID"
20
+ task :deputize => :environment do
21
+ puts
22
+ if ENV['uid'].blank?
23
+ puts "User's CalNet UID required."
24
+ puts "Usage: rake #{$*} uid=INTEGER"
25
+ puts
26
+ exit
27
+ end
28
+ if !User.exists?(:uid => ENV['uid'])
29
+ puts "No user found with uid=#{ENV['uid']}."
30
+ puts
31
+ exit
32
+ end
33
+ user = User.find(:first, :conditions => { :uid => ENV['uid'] })
34
+ puts "Found user #{user.displayname}. Deputizing..."
35
+ user.deputize
36
+ puts "User deputized: #{user.is_administrator?}"
37
+ puts
38
+ end
39
+
40
+ end
@@ -0,0 +1,52 @@
1
+ namespace :db do
2
+
3
+ desc "Create yml fixtures for given model in database\n" <<
4
+ "rake db:extract_fixtures_from pages"
5
+ task :extract_fixtures_from => :environment do
6
+ me = $*.shift
7
+ while( table_name = $*.shift )
8
+ File.open("#{RAILS_ROOT}/db/#{table_name}.yml", 'w') do |file|
9
+ data = table_name.singularize.capitalize.constantize.find(
10
+ :all).collect(&:attributes)
11
+ file.write data.inject({}) { |hash, record|
12
+ record.delete('created_at')
13
+ record.delete('updated_at')
14
+ hash["#{table_name}_#{record['id']}"] = record
15
+ hash
16
+ }.to_yaml
17
+ end
18
+ end
19
+ exit
20
+ end
21
+
22
+ desc "Dump MYSQL table descriptions."
23
+ task :describe => :environment do
24
+ puts
25
+ puts "FYI: This task ONLY works on MYSQL databases."
26
+ puts
27
+ config = ActiveRecord::Base.connection.instance_variable_get(:@config)
28
+ #=> {:adapter=>"mysql", :host=>"localhost", :password=>nil, :username=>"root", :database=>"my_development", :encoding=>"utf8"}
29
+
30
+ tables = ActiveRecord::Base.connection.execute('show tables;')
31
+ while( table = tables.fetch_row ) do
32
+ puts "Table: #{table}"
33
+
34
+ # may have to include host and port
35
+ system("mysql --table=true " <<
36
+ "--user=#{config[:username]} " <<
37
+ "--password='#{config[:password]}' " <<
38
+ "--execute='describe #{table}' " <<
39
+ config[:database]);
40
+
41
+ #
42
+ # mysql formats the table well so doing it by hand is something that
43
+ # will have to wait until I feel like wasting my time
44
+ #
45
+ # columns = ActiveRecord::Base.connection.execute("describe #{table};")
46
+ # while( column = columns.fetch_hash ) do
47
+ # puts column.keys Extra Default Null Type Field Key
48
+ # end
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,68 @@
1
+ #
2
+ # This file has been copied from rails
3
+ # .../rails-2.3.5/lib/tasks/documentation.rake
4
+ # so that parts of it could be modified.
5
+
6
+ namespace :doc do |doc|
7
+
8
+ # Rake::RDocTask.new("app") { |rdoc|
9
+ #
10
+ # We cannot overwrite or override an RDoc rake task.
11
+ # Redefining it here actually creates another
12
+ # of the same name and both are run when
13
+ # `rake doc:app` is called. The Rakefile
14
+ # is modified to handle the modifications.
15
+ #
16
+ # Actually, that's not entirely true. This would
17
+ # add another task, but you can remove and override
18
+ # a task. The rdoc_rails plugin was overriding my
19
+ # override, which caused all the frustration!!!
20
+ #
21
+ # }
22
+
23
+ plugins = FileList['vendor/plugins/**'].collect { |plugin|
24
+ File.basename(plugin) }
25
+
26
+ namespace :plugins do
27
+ # Define doc tasks for each plugin
28
+ plugins.each do |plugin|
29
+
30
+ # clear rails' Rake::Task of the same name
31
+ Rake::Task[plugin].clear_actions
32
+ Rake::Task[plugin].clear_prerequisites
33
+
34
+ Rake::RDocTask.new(plugin) { |rdoc|
35
+ plugin_base = "vendor/plugins/#{plugin}"
36
+ ENV['format'] ||= 'railsfish'
37
+ rdoc.rdoc_dir = "doc/plugins/#{plugin}"
38
+ rdoc.template = ENV['template'] if ENV['template']
39
+ rdoc.title = "#{plugin.titlecase} Plugin Documentation"
40
+ rdoc.options << '--line-numbers' << '--inline-source'
41
+ rdoc.options << '--charset' << 'utf-8'
42
+ rdoc.options << '--format' << ENV['format']
43
+ rdoc.rdoc_files.include("#{plugin_base}/lib/**/*.rb")
44
+ rdoc.rdoc_files.include("#{plugin_base}/app/**/*.rb")
45
+
46
+ %w( README README.rdoc ).each do |readme|
47
+ if File.exist?("#{plugin_base}/#{readme}")
48
+ rdoc.main = "#{plugin_base}/#{readme}"
49
+ break
50
+ end
51
+ end
52
+ %w( TODO.org MIT-LICENSE LICENSE CHANGELOG README README.rdoc ).each do |possible_file|
53
+ if File.exist?("#{plugin_base}/#{possible_file}")
54
+ rdoc.rdoc_files.include("#{plugin_base}/#{possible_file}")
55
+ end
56
+ end
57
+ }
58
+
59
+ end
60
+ end
61
+
62
+ task :parse_readme => :environment do
63
+ require 'rdoc/markup/to_html'
64
+ h = RDoc::Markup::ToHtml.new
65
+ puts h.convert( File.read('README.rdoc') )
66
+ end
67
+
68
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # This is from Advanced Rails Recipes, page 277
3
+ #
4
+ namespace :test do
5
+
6
+ desc 'Tracks test coverage with rcov'
7
+ task :coverage do
8
+ rm_f "coverage"
9
+ rm_f "coverage.data"
10
+
11
+ unless PLATFORM['i386-mswin32']
12
+ rcov = "rcov --sort coverage --rails --aggregate coverage.data " <<
13
+ "--text-summary -Ilib -T " <<
14
+ "-x gems/*,db/migrate/*,jrails/*/*" <<
15
+ ',\(eval\),\(recognize_optimized\),\(erb\)' << # needed in jruby
16
+ ",yaml,yaml/*,lib/tmail/parser.y,jruby.jar!/*" << # needed in jruby
17
+ ",html_test/*/*" <<
18
+ ",html_test_extension/*/*"
19
+ else
20
+ rcov = "rcov.cmd --sort coverage --rails --aggregate " <<
21
+ "coverage.data --text-summary -Ilib -T"
22
+ end
23
+
24
+ dirs = Dir.glob("test/**/*_test.rb").collect{|f|File.dirname(f)}.uniq
25
+ lastdir = dirs.pop
26
+ dirs.each do |dir|
27
+ system("#{rcov} --no-html #{dir}/*_test.rb")
28
+ end
29
+ system("#{rcov} --html #{lastdir}/*_test.rb") unless lastdir.nil?
30
+
31
+ unless PLATFORM['i386-mswin32']
32
+ # jruby-1.5.0.RC1 > PLATFORM
33
+ # => "java"
34
+ # system("open coverage/index.html") if PLATFORM['darwin']
35
+ system("open coverage/index.html")
36
+ else
37
+ system("\"C:/Program Files/Mozilla Firefox/firefox.exe\" " +
38
+ "coverage/index.html")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ namespace :ccls do
2
+ desc "Sync extra files from CCLS engine."
3
+ task :sync do
4
+
5
+ # How to make this work ONLY for apps and not self/plugin/engine.
6
+
7
+ FileUtils.mkdir_p('db/migrate') unless File.directory?('db/migrate')
8
+ rsync_command = <<-EOF.gsub(/\s+/,' ').squish!
9
+ rsync -ruv
10
+ --exclude='versions'
11
+ vendor/plugins/ucb_ccls_engine/db/migrate db
12
+ EOF
13
+ system rsync_command
14
+
15
+ FileUtils.mkdir_p('public') unless File.directory?('public')
16
+ rsync_command = <<-EOF.gsub(/\s+/,' ').squish!
17
+ rsync -ruv
18
+ --exclude='versions'
19
+ vendor/plugins/ucb_ccls_engine/public .
20
+ EOF
21
+ system rsync_command
22
+
23
+ rsync_command = <<-EOF.gsub(/\s+/,' ').squish!
24
+ rsync -ruv
25
+ --exclude='app'
26
+ --exclude='assets'
27
+ --exclude='config'
28
+ --exclude='db'
29
+ --exclude='extensions'
30
+ --exclude='fixtures'
31
+ --exclude='helpers'
32
+ --exclude='log'
33
+ --exclude='versions'
34
+ --exclude='test_helper.rb'
35
+ --exclude='engine_\*_test.rb'
36
+ vendor/plugins/ucb_ccls_engine/test .
37
+ EOF
38
+ system rsync_command
39
+ end
40
+ end
41
+
42
+ #
43
+ # If the gem doesn't exist then this would block
44
+ # the usage of rake gems:install
45
+ # If we wrap it in this condition, it works fine.
46
+ #
47
+ if Gem.searcher.find('paperclip')
48
+ require 'paperclip'
49
+ load "tasks/paperclip.rake"
50
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jakewendt-photos
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
11
+ platform: ruby
12
+ authors:
13
+ - George 'Jake' Wendt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-25 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: i18n
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 7
34
+ version: 0.3.7
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rails
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 2
48
+ version: "2"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: paperclip
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: jakewendt-rails_helpers
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: jakewendt-ruby_extension
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :runtime
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: ryanb-acts-as-list
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :runtime
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: jakewendt-calnet_authenticated
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ type: :runtime
120
+ version_requirements: *id007
121
+ - !ruby/object:Gem::Dependency
122
+ name: jakewendt-authorized
123
+ prerelease: false
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ type: :runtime
134
+ version_requirements: *id008
135
+ description: longer description of your gem
136
+ email: github@jake.otherinbox.com
137
+ executables: []
138
+
139
+ extensions: []
140
+
141
+ extra_rdoc_files:
142
+ - README.rdoc
143
+ files:
144
+ - app/controllers/photos_controller.rb
145
+ - app/models/photo.rb
146
+ - app/views/photos/_form.html.erb
147
+ - app/views/photos/_photo.html.erb
148
+ - app/views/photos/edit.html.erb
149
+ - app/views/photos/index.html.erb
150
+ - app/views/photos/new.html.erb
151
+ - app/views/photos/show.html.erb
152
+ - config/photo.yml
153
+ - config/routes.rb
154
+ - generators/photos/USAGE
155
+ - generators/photos/photos_generator.rb
156
+ - generators/photos/templates/functional/photos_controller_test.rb
157
+ - generators/photos/templates/images/full/missing.png
158
+ - generators/photos/templates/images/large/missing.png
159
+ - generators/photos/templates/images/medium/missing.png
160
+ - generators/photos/templates/images/original/missing.png
161
+ - generators/photos/templates/images/small/missing.png
162
+ - generators/photos/templates/migrations/add_attachments_image_to_photo.rb
163
+ - generators/photos/templates/migrations/create_photos.rb
164
+ - generators/photos/templates/unit/photo_test.rb
165
+ - lib/photos.rb
166
+ - lib/photos/factories.rb
167
+ - lib/photos/factory_test_helper.rb
168
+ - lib/photos/file_utils_extension.rb
169
+ - lib/photos/pending.rb
170
+ - lib/photos/tasks.rb
171
+ - lib/tasks/application.rake
172
+ - lib/tasks/database.rake
173
+ - lib/tasks/documentation.rake
174
+ - lib/tasks/rcov.rake
175
+ - lib/tasks/ucb_ccls_engine_tasks.rake
176
+ - README.rdoc
177
+ has_rdoc: true
178
+ homepage: http://github.com/jakewendt/photos
179
+ licenses: []
180
+
181
+ post_install_message:
182
+ rdoc_options:
183
+ - --charset=UTF-8
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ hash: 3
192
+ segments:
193
+ - 0
194
+ version: "0"
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ none: false
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ hash: 3
201
+ segments:
202
+ - 0
203
+ version: "0"
204
+ requirements: []
205
+
206
+ rubyforge_project:
207
+ rubygems_version: 1.3.7
208
+ signing_key:
209
+ specification_version: 3
210
+ summary: one-line summary of your gem
211
+ test_files: []
212
+