t-minus 0.3.0 → 0.3.1

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.
@@ -0,0 +1,19 @@
1
+ class PrelaunchController < ActionController::Base
2
+ layout 'prelaunch'
3
+
4
+ def new
5
+ @prelaunch_subscriber = PrelaunchSubscriber.new
6
+ end
7
+
8
+ def create
9
+ @prelaunch_subscriber = PrelaunchSubscriber.new(params[:prelaunch_subscriber])
10
+ if @prelaunch_subscriber.save
11
+ redirect_to root_url, :notice => <<NOTICE
12
+ <p>Thank you for your interest.</p>
13
+ <p>We have sent you an email to confirm your subscription to our prelaunch mailing list.</p>
14
+ NOTICE
15
+ else
16
+ render :action => 'new'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ class PrelaunchSubscriber < ActiveRecord::Base
2
+ validates_presence_of :email, :message => 'Please enter your email address first.'
3
+ validates_uniqueness_of :email, :message => 'That email is already on the list.'
4
+ validates_format_of :email,
5
+ :with => /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i,
6
+ :message => 'That email address doesn\'t look right.'
7
+
8
+ after_save :add_to_campaign_monitor, :if => :campaign_monitor_configured?
9
+
10
+ private
11
+
12
+ def add_to_campaign_monitor
13
+ list_id = PRELAUNCH_CONFIG[:campaign_monitor_list_id]
14
+ CreateSend::Subscriber.add(list_id, email, "", [], true)
15
+ end
16
+
17
+ def campaign_monitor_configured?
18
+ PRELAUNCH_CONFIG[:campaign_monitor_api_key].present? &&
19
+ PRELAUNCH_CONFIG[:campaign_monitor_list_id].present?
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8"/>
5
+ <title><%= Rails.application.class.to_s.split('::').first.titleize %></title>
6
+ <%= stylesheet_link_tag 'prelaunch' %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
@@ -0,0 +1,17 @@
1
+ <% if flash[:notice] %>
2
+ <%= flash[:notice].html_safe %>
3
+ <% else %>
4
+ <p>Our new website is launching soon.</p>
5
+ <p>Add your name to the list and you will be the first to know when we are ready.</p>
6
+ <%= form_for @prelaunch_subscriber, :url => prelaunch_path do |f| %>
7
+ <div class="field">
8
+ <%= f.text_field :email %>
9
+ <% if @prelaunch_subscriber.errors[:email] %>
10
+ <div class="form-error"><%= @prelaunch_subscriber.errors[:email].first %></div>
11
+ <% end %>
12
+ </div>
13
+ <div class="actions">
14
+ <%= f.submit 'Add me to the list' %>
15
+ </div>
16
+ <% end %>
17
+ <% end %>
@@ -0,0 +1 @@
1
+ default: --format pretty
@@ -0,0 +1,10 @@
1
+ prelaunch_config_path = "#{Rails.root}/config/prelaunch_config.yml"
2
+ if File.exists?(prelaunch_config_path)
3
+ raw_config = File.read(prelaunch_config_path)
4
+ PRELAUNCH_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys
5
+
6
+ campaign_monitor_api_key = PRELAUNCH_CONFIG[:campaign_monitor_api_key]
7
+ CreateSend.api_key(campaign_monitor_api_key) if campaign_monitor_api_key.present?
8
+ else
9
+ PRELAUNCH_CONFIG = {}
10
+ end
@@ -0,0 +1,15 @@
1
+ module TMinus
2
+ module Routes
3
+ def Routes.map
4
+ Rails.application.routes.draw do
5
+ post '/' => 'prelaunch#create', :as => :prelaunch
6
+ root :to => 'prelaunch#new'
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ if PRELAUNCH_CONFIG[:active]
13
+ Rails.application.routes.clear!
14
+ TMinus::Routes.map
15
+ end
@@ -0,0 +1,20 @@
1
+ module Erb
2
+ module Generators
3
+ class TMinusGenerator < Rails::Generators::Base
4
+ desc 'Generates ERB view template for T-Minus'
5
+ source_root File.expand_path('../../../../app/views/', __FILE__)
6
+
7
+ def create_prelaunch_directory
8
+ empty_directory 'app/views/prelaunch'
9
+ end
10
+
11
+ def copy_view_file
12
+ copy_file 'prelaunch/new.html.erb', 'app/views/prelaunch/new.html.erb'
13
+ end
14
+
15
+ def copy_layout_file
16
+ copy_file 'layouts/prelaunch.html.erb', 'app/views/layouts/prelaunch.html.erb'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Haml
2
+ module Generators
3
+ class TMinusGenerator < ::Rails::Generators::Base
4
+ desc 'Generates Haml view template for T-Minus'
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def create_prelaunch_directory
8
+ empty_directory 'app/views/prelaunch'
9
+ end
10
+
11
+ def copy_view_file
12
+ copy_file 'new.html.haml', 'app/views/prelaunch/new.html.haml'
13
+ end
14
+
15
+ def copy_layout_file
16
+ copy_file 'prelaunch.html.haml', 'app/views/layouts/prelaunch.html.haml'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ - if flash[:notice]
2
+ = flash[:notice].html_safe
3
+ - else
4
+ %p Our new website is launching soon.
5
+ %p Add your name to the list and you will be the first to know when we are ready.
6
+ = form_for @prelaunch_subscriber, :url => prelaunch_path do |f|
7
+ .field
8
+ = f.text_field :email
9
+ - if @prelaunch_subscriber.errors[:email]
10
+ .form-error= @prelaunch_subscriber.errors[:email].first
11
+ .actions
12
+ = f.submit 'Add me to the list'
@@ -0,0 +1,9 @@
1
+ !!!
2
+ %html{:lang => 'en'}
3
+ %head
4
+ %meta{:charset => 'UTF-8'}
5
+ %title
6
+ = stylesheet_link_tag 'prelaunch'
7
+ = csrf_meta_tag
8
+ %body
9
+ = yield
@@ -0,0 +1,40 @@
1
+ module Rspec
2
+ module Generators
3
+ class TMinusGenerator < ::Rails::Generators::Base
4
+ desc 'Generates view spec for T-Minus'
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :template_engine
7
+
8
+ def create_view_spec_directory
9
+ empty_directory 'spec/views/prelaunch'
10
+ end
11
+
12
+ def copy_view_file
13
+ template 'view_spec.erb',
14
+ "spec/views/prelaunch/new.html.#{options[:template_engine]}_spec.rb"
15
+ end
16
+
17
+ def include_test_helper
18
+ if File.exists? File.expand_path('spec/spec_helper.rb', @_source_root)
19
+ append_file 'spec/spec_helper.rb', "require 't-minus/test_helper'"
20
+ else
21
+ create_file 'spec/spec_helper.rb', <<-FILE
22
+ ENV['RAILS_ENV'] ||= 'test'
23
+ require File.expand_path('../../config/environment', __FILE__)
24
+ require 'rspec/rails'
25
+
26
+ Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
27
+
28
+ RSpec.configure do |config|
29
+ config.mock_with :rspec
30
+ config.fixture_path = "\#{::Rails.root}/spec/fixtures"
31
+ config.use_transactional_fixtures = true
32
+ end
33
+
34
+ require 't-minus/test_helper'
35
+ FILE
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'prelaunch/new.html.<%= options[:template_engine] %>' do
4
+ before do
5
+ simulate_prelaunch_routes
6
+ assign(:prelaunch_subscriber, PrelaunchSubscriber.new)
7
+ end
8
+
9
+ it 'should render successfully' do
10
+ render
11
+ end
12
+
13
+ after { restore_routes }
14
+ end
@@ -0,0 +1,12 @@
1
+ module TMinus
2
+ module Generators
3
+ class ControllerGenerator < Rails::Generators::Base
4
+ desc 'Generates the PrelaunchController for T-Minus'
5
+ source_root File.expand_path('../../../../app/controllers/', __FILE__)
6
+
7
+ def copy_controller_file
8
+ copy_file 'prelaunch_controller.rb', 'app/controllers/prelaunch_controller.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module TMinus
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ desc 'Generates configuration and migration files for T-Minus'
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ hook_for :template_engine, :as => :t_minus
12
+ hook_for :test_framework, :as => :t_minus
13
+
14
+ def copy_configuration_file
15
+ copy_file 'prelaunch_config.yml', 'config/prelaunch_config.yml'
16
+ end
17
+
18
+ def generate_migration
19
+ migration_template 'migration.rb', "db/migrate/create_#{table_name}"
20
+ end
21
+
22
+ def create_css_file
23
+ create_file 'public/stylesheets/prelaunch.css'
24
+ end
25
+
26
+ def self.next_migration_number(dirname)
27
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
28
+ end
29
+
30
+ private
31
+
32
+ def table_name
33
+ 'prelaunch_subscribers'
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ module TMinus
2
+ module Generators
3
+ class ModelGenerator < Rails::Generators::Base
4
+ desc 'Generates the PrelaunchSubscriber model for T-Minus'
5
+ source_root File.expand_path('../../../../app/models/', __FILE__)
6
+
7
+ def copy_controller_file
8
+ copy_file 'prelaunch_subscriber.rb', 'app/models/prelaunch_subscriber.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class Create<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= table_name %>) do |t|
4
+ t.string :email
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :<%= table_name %>
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ development:
2
+ active: false
3
+
4
+ test:
5
+ active: false
6
+
7
+ production:
8
+ active: true
9
+ # campaign_monitor_api_key:
10
+ # campaign_monitor_list_id:
@@ -0,0 +1,31 @@
1
+ module TestUnit
2
+ module Generators
3
+ class TMinusGenerator < ::Rails::Generators::Base
4
+ desc 'Generates view spec for T-Minus'
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :template_engine
7
+
8
+ def create_view_test_directory
9
+ empty_directory 'test/views/prelaunch'
10
+ end
11
+
12
+ def copy_view_file
13
+ template 'view_test.erb',
14
+ "test/views/prelaunch/new.html.#{options[:template_engine]}_test.rb"
15
+ end
16
+
17
+ def include_test_helper
18
+ if File.exists? File.expand_path('test/test_helper.rb', @_source_root)
19
+ append_file 'test/test_helper.rb', "require 't-minus/test_helper'"
20
+ else
21
+ create_file 'test/test_helper.rb', <<-FILE
22
+ ENV['RAILS_ENV'] = 'test'
23
+ require File.expand_path('../../config/environment', __FILE__)
24
+ require 'rails/test_help'
25
+ require 't-minus/test_helper'
26
+ FILE
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class PrelaunchNewViewTest < ActionView::TestCase
4
+ def setup
5
+ simulate_prelaunch_routes
6
+ @prelaunch_subscriber = PrelaunchSubscriber.new
7
+ end
8
+
9
+ test 'should render successfully' do
10
+ render :template => 'prelaunch/new'
11
+ end
12
+
13
+ def teardown
14
+ restore_routes
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ require 't-minus/engine' if defined?(Rails)
@@ -0,0 +1,8 @@
1
+ require 't-minus'
2
+ require 'createsend'
3
+ require 'rails'
4
+
5
+ module TMinus
6
+ class Engine < Rails::Engine
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ def simulate_prelaunch_routes
2
+ Rails.application.routes.clear!
3
+ TMinus::Routes.map
4
+ end
5
+
6
+ def restore_routes
7
+ Rails.application.routes.clear!
8
+ load(File.expand_path('config/routes.rb', Rails.root))
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe PrelaunchController do
4
+ describe 'new action' do
5
+ it 'should be successful' do
6
+ get :new
7
+ assigns(:prelaunch_subscriber).should be_a(PrelaunchSubscriber)
8
+ end
9
+ end
10
+
11
+ describe 'create action' do
12
+ it 'should be successful' do
13
+ PrelaunchSubscriber.any_instance.expects(:save).returns(true)
14
+ post :create
15
+ flash[:notice].should_not be_nil
16
+ response.should redirect_to(root_url)
17
+ end
18
+
19
+ it 'should render new template if unsuccessful' do
20
+ PrelaunchSubscriber.any_instance.expects(:save).returns(false)
21
+ post :create
22
+ response.should render_template('prelaunch/new')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe PrelaunchSubscriber do
4
+ before do
5
+ @prelaunch_subscriber = PrelaunchSubscriber.new(:email => 'bob@somedomain.com')
6
+ end
7
+
8
+ it 'should be valid' do
9
+ @prelaunch_subscriber.should be_valid
10
+ end
11
+
12
+ describe 'add_to_campaign_monitor' do
13
+ it 'should be successful' do
14
+ CreateSend::Subscriber.expects(:add).returns(true)
15
+ @prelaunch_subscriber.send(:add_to_campaign_monitor)
16
+ end
17
+ end
18
+
19
+ describe 'campaign_monitor_configured?' do
20
+ it 'should be successful' do
21
+ @prelaunch_subscriber.send(:campaign_monitor_configured?).should == true
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../test/rails_app/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.use_transactional_fixtures = true
12
+ config.use_instantiated_fixtures = false
13
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
14
+ config.global_fixtures = :all
15
+ config.mock_with :mocha
16
+
17
+ config.before(:suite) do
18
+ # Make a copy of the clean test app and install T-Minus
19
+ @test_dir = File.expand_path(File.dirname(__FILE__) + '/../test/')
20
+ @test_app_path = File.expand_path('rails_app', @test_dir)
21
+ @orig_app_path = File.expand_path('orig_app', @test_dir)
22
+ FileUtils.cp_r(@test_app_path, @orig_app_path)
23
+ FileUtils.chdir(@test_app_path) do
24
+ `rails generate t_minus:install`
25
+ `rake db:migrate`
26
+ end
27
+
28
+ TMinus::Routes.map
29
+ end
30
+
31
+ config.after(:suite) do
32
+ # Restore the clean test app
33
+ FileUtils.rm_rf(@test_app_path)
34
+ FileUtils.mv(@orig_app_path, @test_app_path)
35
+ end
36
+
37
+ config.before(:each) do
38
+ Object.redefine_const(:PRELAUNCH_CONFIG, {
39
+ :active => true,
40
+ :campaign_monitor_api_key => 'somekey',
41
+ :campaign_monitor_list_id => 'somelistid'
42
+ })
43
+ CreateSend.api_key PRELAUNCH_CONFIG[:campaign_monitor_api_key]
44
+ end
45
+ end
46
+
47
+ class Module
48
+ def redefine_const(name, value)
49
+ __send__(:remove_const, name) if const_defined?(name)
50
+ const_set(name, value)
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'prelaunch/new.html.erb' do
4
+ before do
5
+ assign(:prelaunch_subscriber, PrelaunchSubscriber.new)
6
+ end
7
+
8
+ it 'should render successfully' do
9
+ render
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'prelaunch/new.html.haml' do
4
+ before do
5
+ assign(:prelaunch_subscriber, PrelaunchSubscriber.new)
6
+ end
7
+
8
+ it 'should render successfully' do
9
+ append_view_path File.expand_path('../../../../lib/generators/haml/templates', __FILE__)
10
+ render :template => 'new.html.haml'
11
+ end
12
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t-minus
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 17
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 3
8
- - 0
9
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - John Grimes
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-17 00:00:00 +10:00
18
+ date: 2011-02-06 00:00:00 +10:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ~>
27
28
  - !ruby/object:Gem::Version
29
+ hash: 15
28
30
  segments:
29
31
  - 0
30
32
  - 2
@@ -39,6 +41,7 @@ dependencies:
39
41
  requirements:
40
42
  - - ~>
41
43
  - !ruby/object:Gem::Version
44
+ hash: 1
42
45
  segments:
43
46
  - 1
44
47
  version: "1"
@@ -52,6 +55,7 @@ dependencies:
52
55
  requirements:
53
56
  - - ~>
54
57
  - !ruby/object:Gem::Version
58
+ hash: 7
55
59
  segments:
56
60
  - 2
57
61
  version: "2"
@@ -65,6 +69,7 @@ dependencies:
65
69
  requirements:
66
70
  - - ~>
67
71
  - !ruby/object:Gem::Version
72
+ hash: 25
68
73
  segments:
69
74
  - 0
70
75
  - 9
@@ -79,6 +84,7 @@ dependencies:
79
84
  requirements:
80
85
  - - ~>
81
86
  - !ruby/object:Gem::Version
87
+ hash: 13
82
88
  segments:
83
89
  - 0
84
90
  - 3
@@ -93,6 +99,7 @@ dependencies:
93
99
  requirements:
94
100
  - - ~>
95
101
  - !ruby/object:Gem::Version
102
+ hash: 5
96
103
  segments:
97
104
  - 0
98
105
  - 7
@@ -107,6 +114,7 @@ dependencies:
107
114
  requirements:
108
115
  - - ~>
109
116
  - !ruby/object:Gem::Version
117
+ hash: 1
110
118
  segments:
111
119
  - 1
112
120
  - 4
@@ -124,6 +132,34 @@ extra_rdoc_files:
124
132
  - LICENSE
125
133
  - README.markdown
126
134
  files:
135
+ - app/views/layouts/prelaunch.html.erb
136
+ - app/views/prelaunch/new.html.erb
137
+ - app/controllers/prelaunch_controller.rb
138
+ - app/models/prelaunch_subscriber.rb
139
+ - config/cucumber.yml
140
+ - config/routes.rb
141
+ - config/initializers/load_prelaunch_config.rb
142
+ - lib/t-minus/test_helper.rb
143
+ - lib/t-minus/engine.rb
144
+ - lib/t-minus.rb
145
+ - lib/generators/rspec/templates/view_spec.erb
146
+ - lib/generators/rspec/t_minus_generator.rb
147
+ - lib/generators/t_minus/templates/migration.rb
148
+ - lib/generators/t_minus/templates/prelaunch_config.yml
149
+ - lib/generators/t_minus/install_generator.rb
150
+ - lib/generators/t_minus/model_generator.rb
151
+ - lib/generators/t_minus/controller_generator.rb
152
+ - lib/generators/test_unit/templates/view_test.erb
153
+ - lib/generators/test_unit/t_minus_generator.rb
154
+ - lib/generators/haml/templates/new.html.haml
155
+ - lib/generators/haml/templates/prelaunch.html.haml
156
+ - lib/generators/haml/t_minus_generator.rb
157
+ - lib/generators/erb/t_minus_generator.rb
158
+ - spec/spec_helper.rb
159
+ - spec/views/prelaunch/new.html.haml_spec.rb
160
+ - spec/views/prelaunch/new.html.erb_spec.rb
161
+ - spec/controllers/prelaunch_controller_spec.rb
162
+ - spec/models/prelaunch_subscriber_spec.rb
127
163
  - LICENSE
128
164
  - README.markdown
129
165
  has_rdoc: true
@@ -140,6 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
176
  requirements:
141
177
  - - ">="
142
178
  - !ruby/object:Gem::Version
179
+ hash: 3
143
180
  segments:
144
181
  - 0
145
182
  version: "0"
@@ -148,6 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
185
  requirements:
149
186
  - - ">="
150
187
  - !ruby/object:Gem::Version
188
+ hash: 23
151
189
  segments:
152
190
  - 1
153
191
  - 3
@@ -160,5 +198,9 @@ rubygems_version: 1.3.7
160
198
  signing_key:
161
199
  specification_version: 3
162
200
  summary: Rails engine and generators that make it easier to create a prelaunch page for your application that can collect email addresses of interested visitors.
163
- test_files: []
164
-
201
+ test_files:
202
+ - spec/spec_helper.rb
203
+ - spec/views/prelaunch/new.html.haml_spec.rb
204
+ - spec/views/prelaunch/new.html.erb_spec.rb
205
+ - spec/controllers/prelaunch_controller_spec.rb
206
+ - spec/models/prelaunch_subscriber_spec.rb