Skip to content

Commit

Permalink
Move images backend into a generator.
Browse files Browse the repository at this point in the history
* Added cucumber coverage for generators using aruba
* Removed images backend from engine
* Removed paperclip dependency from gem spec
  • Loading branch information
gvarela committed May 29, 2012
1 parent 1b8386a commit 0ce5b68
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 66 deletions.
13 changes: 13 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 6 additions & 10 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 0 additions & 25 deletions db/schema.rb

This file was deleted.

63 changes: 63 additions & 0 deletions features/generators/install.feature
Original file line number Diff line number Diff line change
@@ -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'"

27 changes: 27 additions & 0 deletions features/step_definitions/generator_steps.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions features/support/aruba.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions lib/generators/mercury/install/images/images_generator.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions lib/generators/mercury/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

Expand All @@ -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]")
Expand Down
6 changes: 2 additions & 4 deletions lib/mercury-rails.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'paperclip'

# module Mercury
# end
module Mercury
end

require 'mercury/engine'

3 changes: 3 additions & 0 deletions lib/mercury/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Mercury
VERSION = '0.4.0'
end
12 changes: 4 additions & 8 deletions mercury-rails.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')


Expand Down
8 changes: 0 additions & 8 deletions script/rails

This file was deleted.

0 comments on commit 0ce5b68

Please sign in to comment.