Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move images backend into a generator.

* Added cucumber coverage for generators using aruba
* Removed images backend from engine
* Removed paperclip dependency from gem spec
  • Loading branch information...
commit 0ce5b689d5988bbf15eede598e987c1988385e1a 1 parent 1b8386a
@gvarela gvarela authored
View
13 Gemfile
@@ -1,2 +1,15 @@
source 'http://rubygems.org'
+
+ #Dependencies for the dummy app
+ gem 'jquery-rails'
+ gem 'sqlite3'
+
+ # Gems used only for assets and not required
+ # in production environments by default.
+ group :assets do
+ gem 'sass-rails'
+ gem 'coffee-rails'
+ gem 'uglifier'
+ end
+
gemspec
View
16 config/routes.rb
@@ -1,13 +1,9 @@
Mercury::Engine.routes.draw do
- match '/editor(/*requested_uri)' => "mercury#edit", :as => :mercury_editor
+ match '/editor(/*requested_uri)' => "mercury#edit", :as => :mercury_editor
- namespace :mercury do
- resources :images
- end
-
- scope '/mercury' do
- match ':type/:resource' => "mercury#resource"
- match 'snippets/:name/options' => "mercury#snippet_options"
- match 'snippets/:name/preview' => "mercury#snippet_preview"
- end
+ scope '/mercury' do
+ match ':type/:resource' => "mercury#resource"
+ match 'snippets/:name/options' => "mercury#snippet_options"
+ match 'snippets/:name/preview' => "mercury#snippet_preview"
+ end
end
View
25 db/schema.rb
@@ -1,25 +0,0 @@
-# encoding: UTF-8
-# This file is auto-generated from the current state of the database. Instead
-# of editing this file, please use the migrations feature of Active Record to
-# incrementally modify your database, and then regenerate this schema definition.
-#
-# Note that this schema.rb definition is the authoritative source for your
-# database schema. If you need to create the application database on another
-# system, you should be using db:schema:load, not running all the migrations
-# from scratch. The latter is a flawed and unsustainable approach (the more migrations
-# you'll amass, the slower it'll run and the greater likelihood for issues).
-#
-# It's strongly recommended to check this file into your version control system.
-
-ActiveRecord::Schema.define(:version => 20110526035601) do
-
- create_table "mercury_images", :force => true do |t|
- t.string "image_file_name"
- t.string "image_content_type"
- t.integer "image_file_size"
- t.datetime "image_updated_at"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
-end
View
63 features/generators/install.feature
@@ -0,0 +1,63 @@
+@announce
+Feature:
+ As a developer
+ In order to use mercury
+ I should be able to use a generator to setup my application
+
+
+ Scenario: A developer I want a basic install of mercury
+ Given I have created a new rails application
+ When I run `bundle exec rails generate mercury:install --trace` interactively
+ And I type "N"
+ And I type "N"
+ Then the following files should exist:
+ | app/assets/javascripts/mercury.js |
+ And the file "config/routes.rb" should contain "mount Mercury::Engine => '/'"
+
+ Scenario: A developer I want a full install of mercury
+ Given I have created a new rails application
+ When I successfully run `bundle exec rails generate mercury:install --full --trace`
+ Then the following files should exist:
+ | app/assets/javascripts/mercury.js |
+ | app/assets/stylesheets/mercury_overrides.css |
+ | app/views/layouts/mercury.html.erb |
+ | lib/mercury/authentication.rb |
+ And the file "config/routes.rb" should contain "mount Mercury::Engine => '/'"
+
+ Scenario: A developer I want to install the image backend for Mercury
+ Given I have created a new rails application
+ When I successfully run `bundle exec rails generate mercury:install:images --trace`
+ Then the following files should exist:
+ | app/controllers/mercury/images_controller.rb |
+ | app/models/mercury/image.rb |
+ And the file "app/models/mercury/image.rb" should contain "class Mercury::Image < ActiveRecord::Base"
+ And should have the migration "create_mercury_images.rb"
+ And the file "config/routes.rb" should contain:
+ """
+ namespace :mercury do
+ resources :images
+ end
+ """
+ And the file "Gemfile" should contain "gem 'paperclip'"
+
+ Scenario: A developer I want to install the image backend for Mercury with Mongoid
+ Given I have created a new rails application
+ When I successfully run `bundle exec rails generate mercury:install:images --orm mongoid --trace`
+ Then the following files should exist:
+ | app/controllers/mercury/images_controller.rb |
+ | app/models/mercury/image.rb |
+ And the file "app/models/mercury/image.rb" should contain:
+ """
+ class Mercury::Image
+ include Mongoid::Document
+ include Mongoid::Paperclip
+ """
+ And should not have the migration "create_mercury_images.rb"
+ And the file "config/routes.rb" should contain:
+ """
+ namespace :mercury do
+ resources :images
+ end
+ """
+ And the file "Gemfile" should contain "gem 'paperclip'"
+
View
27 features/step_definitions/generator_steps.rb
@@ -0,0 +1,27 @@
+When /^I add Mercury as a gem dependency$/ do
+ append_to_file('Gemfile', %{\ngem "mercury-rails", :path => "#{File.expand_path('../../../', __FILE__)}"\n})
+end
+
+When "I have created a new rails application" do
+ step %{I reset Bundler environment variable}
+ step %{I successfully run `bundle exec rails new testapp --skip-bundle`}
+ step %{I cd to "testapp"}
+ step %{I add Mercury as a gem dependency}
+ step %{I run `bundle install --local`}
+end
+
+Then /^the file "([^"]*)" should contain:$/ do |file, partial_content|
+ check_file_content(file, partial_content, true)
+end
+
+Then /^should have the migration "([^"]*)"$/ do |migration|
+ in_current_dir do
+ Dir["db/migrate/*_#{migration}"].length.should == 1
+ end
+end
+
+Then /^should not have the migration "([^"]*)"$/ do |migration|
+ in_current_dir do
+ Dir["db/migrate/*_#{migration}"].length.should == 0
+ end
+end
View
28 features/support/aruba.rb
@@ -0,0 +1,28 @@
+BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
+ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
+
+Before do
+ if ! ENV['BUNDLE_GEMFILE'].include?(Dir.pwd)
+ ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE'])
+ end
+end
+
+After do
+ ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
+ ENV[key] = value
+ end
+end
+
+When /^I reset Bundler environment variable$/ do
+ BUNDLE_ENV_VARS.each do |key|
+ ENV[key] = nil
+ end
+end
+
+Before do
+ @aruba_timeout_seconds = 20
+end
+
+Before('@slow') do
+ @aruba_timeout_seconds = 180
+end
View
1  features/support/env.rb
@@ -6,6 +6,7 @@
require 'cucumber/rails'
require 'capybara/firebug'
+require 'aruba/cucumber'
# You can enable firebug in your tests by tagging them @firebug.
# To change the version of firebug use the FIREBUG_VERSION environment variable.
View
42 lib/generators/mercury/install/images/images_generator.rb
@@ -0,0 +1,42 @@
+require 'rails/generators/active_record'
+module Mercury
+ module Generators
+ module Install
+ class ImagesGenerator < Rails::Generators::Base
+ include Rails::Generators::Migration
+ source_root File.expand_path("../templates", __FILE__)
+
+ class_option :orm, :default => 'active_record', :banner => 'mongoid',
+ :desc => 'ORM for required models -- active_record, or mongoid'
+
+ def copy_models
+ if options[:orm] == 'mongoid'
+ copy_file 'mongoid_paperclip_image.rb', 'app/models/mercury/image.rb'
+ else
+ copy_file 'ar_paperclip_image.rb', 'app/models/mercury/image.rb'
+ migration_template 'ar_paperclip_image_migration.rb', 'db/migrate/create_mercury_images.rb'
+ end
+ end
+
+ def copy_controller
+ copy_file 'images_controller.rb', 'app/controllers/mercury/images_controller.rb'
+ end
+
+ def add_routes
+ route %Q{ namespace :mercury do
+ resources :images
+ end}
+ end
+
+ def add_gemfile_dependencies
+ prepend_to_file "Gemfile", %Q{gem 'paperclip'}
+ end
+
+ # Implement the required interface for Rails::Generators::Migration.
+ def self.next_migration_number(dirname) #:nodoc:
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
+ end
+ end
+ end
+ end
+end
View
4 app/models/mercury/image.rb → ...ll/images/templates/ar_paperclip_image.rb
@@ -2,7 +2,9 @@ class Mercury::Image < ActiveRecord::Base
self.table_name = :mercury_images
- has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
+ has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" },
+ :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
+ :url => "/system/:attachment/:id/:style/:filename"
delegate :url, :to => :image
View
0  ...e/20110526035601_create_mercury_images.rb → ...templates/ar_paperclip_image_migration.rb
File renamed without changes
View
0  app/controllers/mercury/images_controller.rb → ...all/images/templates/images_controller.rb
File renamed without changes
View
0  ...tall/templates/mongoid_paperclip_image.rb → ...ages/templates/mongoid_paperclip_image.rb
File renamed without changes
View
10 lib/generators/mercury/install/install_generator.rb
@@ -5,9 +5,6 @@ class InstallGenerator < Rails::Generators::Base
desc "Installs Mercury into your application by copying the configuration file."
- class_option :orm, :default => 'active_record', :banner => 'mongoid',
- :desc => 'ORM for required models -- active_record, or mongoid'
-
class_option :full, :type => :boolean, :aliases => '-g',
:desc => 'Full installation will install the layout and css overrides for easier customization.'
@@ -19,13 +16,6 @@ def add_routes
route %Q{mount Mercury::Engine => '/'}
end
- def copy_models
- if options[:orm] == 'mongoid'
- copy_file 'lib/generators/mercury/install/templates/mongoid_paperclip_image.rb', 'app/models/mercury/image.rb'
- else
- copy_file 'app/models/mercury/image.rb' if options[:full]
- end
- end
def copy_layout_and_css_overrides
if options[:full] || yes?("Install the layout and CSS overrides files? [yN]")
View
6 lib/mercury-rails.rb
@@ -1,7 +1,5 @@
-require 'paperclip'
-
-# module Mercury
-# end
+module Mercury
+end
require 'mercury/engine'
View
3  lib/mercury/version.rb
@@ -0,0 +1,3 @@
+module Mercury
+ VERSION = '0.4.0'
+end
View
12 mercury-rails.gemspec
@@ -1,12 +1,13 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
+require 'mercury/version'
Gem::Specification.new do |s|
# General Gem Information
s.name = 'mercury-rails'
s.date = '2011-11-15'
- s.version = '0.3.1'
+ s.version = Mercury::VERSION
s.authors = ['Jeremy Jackson']
s.email = ['jejacks0n@gmail.com']
s.homepage = 'http://github.com/jejacks0n/mercury'
@@ -17,28 +18,23 @@ Gem::Specification.new do |s|
# Runtime Dependencies
s.add_runtime_dependency('rails', '~> 3.2')
- s.add_runtime_dependency('paperclip', '>= 2.5.2')
s.add_runtime_dependency('coffee-script-source', '1.2.0')
s.add_runtime_dependency('coffee-script')
-
# Development Dependencies
s.add_development_dependency('sprockets', '~> 2.1')
s.add_development_dependency('rocco')
s.add_development_dependency('uglifier')
- s.add_development_dependency('jquery-rails')
- s.add_development_dependency('sqlite3')
s.add_development_dependency('sprockets-rails')
- # These were breaking dev / test env on ruby 1.9.3-p194 with latest bundler and latest rails
- # s.add_development_dependency('ruby-debug19')
-
+ # Testing dependencies
s.add_development_dependency('rspec-core', '>= 2.8.0')
s.add_development_dependency('evergreen', '>= 1.0.0')
s.add_development_dependency('selenium-webdriver', '>= 2.20.0')
s.add_development_dependency('cucumber-rails', '>= 1.3.0')
s.add_development_dependency('capybara')
s.add_development_dependency('capybara-firebug', '>= 1.1.0')
+ s.add_development_dependency('aruba')
s.add_development_dependency('database_cleaner')
View
8 script/rails
@@ -1,8 +0,0 @@
-#!/usr/bin/env ruby
-# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
-
-ENGINE_ROOT = File.expand_path('../..', __FILE__)
-ENGINE_PATH = File.expand_path('../../lib/mercury/engine', __FILE__)
-
-require 'rails/all'
-require 'rails/engine/commands'
Please sign in to comment.
Something went wrong with that request. Please try again.