Skip to content
Browse files

subscriber list, top changed tweet, top changed emails through amazon…

… ses
  • Loading branch information...
1 parent f6aaf1a commit efa0fcca83fdf591d67ad74400d4e079ac9952b5 @browep committed
Showing with 608 additions and 13 deletions.
  1. +1 −1 Gemfile
  2. +10 −0 Gemfile.lock
  3. +5 −1 app/controllers/entries_controller.rb
  4. +55 −0 app/controllers/subscribers_controller.rb
  5. +2 −0 app/helpers/subscriber_helper.rb
  6. +2 −0 app/helpers/subscribers_helper.rb
  7. +12 −0 app/mailers/alert_mailer.rb
  8. +8 −0 app/models/subscriber.rb
  9. +6 −0 app/views/alert_mailer/top_changed_email.html.erb
  10. +1 −0 app/views/alert_mailer/top_changed_text.html.erb
  11. +4 −0 app/views/base/_flash.html.erb
  12. +17 −0 app/views/entries/index.html.erb
  13. +1 −3 app/views/layouts/application.html.erb
  14. +23 −0 app/views/layouts/email.html.erb
  15. +17 −0 app/views/subscribers/_form.html.erb
  16. +6 −0 app/views/subscribers/edit.html.erb
  17. +21 −0 app/views/subscribers/index.html.erb
  18. +5 −0 app/views/subscribers/new.html.erb
  19. +5 −0 app/views/subscribers/show.html.erb
  20. +3 −0 config/application.rb
  21. +2 −0 config/environments/development.rb
  22. +3 −0 config/initializers/amazon_ses.rb
  23. +2 −0 config/routes.rb
  24. +12 −0 db/migrate/20110225030804_add_emails_contacts.rb
  25. +9 −0 db/migrate/20110226013757_add_index_on_subscriber_address.rb
  26. +9 −1 db/schema.rb
  27. +18 −4 lib/core.rb
  28. +12 −0 lib/tasks/update.rake
  29. +5 −0 lib/util.rb
  30. +3 −3 public/stylesheets/application.css
  31. +56 −0 public/stylesheets/scaffold.css
  32. +5 −0 spec/controllers/subscriber_controller_spec.rb
  33. +127 −0 spec/controllers/subscribers_controller_spec.rb
  34. +15 −0 spec/helpers/subscriber_helper_spec.rb
  35. +15 −0 spec/helpers/subscribers_helper_spec.rb
  36. +5 −0 spec/mailers/alert_mailer_spec.rb
  37. +5 −0 spec/models/subscriber_spec.rb
  38. +11 −0 spec/requests/subscribers_spec.rb
  39. +35 −0 spec/routing/subscribers_routing_spec.rb
  40. +15 −0 spec/views/subscribers/edit.html.erb_spec.rb
  41. +14 −0 spec/views/subscribers/index.html.erb_spec.rb
  42. +15 −0 spec/views/subscribers/new.html.erb_spec.rb
  43. +11 −0 spec/views/subscribers/show.html.erb_spec.rb
View
2 Gemfile
@@ -20,7 +20,7 @@ gem 'oauth'
gem 'rspec'
gem 'rspec-rails'
gem 'httparty'
-#gem 'parsedate'
+gem "aws-ses", "~> 0.4.1", :require => 'aws/ses'
# Use unicorn as the web server
# gem 'unicorn'
View
10 Gemfile.lock
@@ -30,6 +30,14 @@ GEM
activesupport (3.0.3)
addressable (2.2.2)
arel (2.0.6)
+ aws-ses (0.4.1)
+ builder
+ builder
+ mail (~> 2.2.5)
+ mime-types
+ mime-types
+ xml-simple
+ xml-simple
builder (2.1.2)
crack (0.1.8)
daemons (1.0.10)
@@ -103,11 +111,13 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
+ xml-simple (1.0.14)
PLATFORMS
ruby
DEPENDENCIES
+ aws-ses (~> 0.4.1)
dispatcher
em-http-request
eventmachine
View
6 app/controllers/entries_controller.rb
@@ -10,8 +10,12 @@ def index
@symbols = Factor.top
-
@recent_entries = Entry.all(:select=>"symbol,source_id,sent_at",:order=>"sent_at DESC",:limit=>45)
+
+ @subscriber = Subscriber.new
+
+ @flash_inner = true
+
end
View
55 app/controllers/subscribers_controller.rb
@@ -0,0 +1,55 @@
+require 'util'
+
+class SubscribersController < ApplicationController
+ include Util
+ def new
+ @subscriber = Subscriber.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @subscriber }
+ end
+ end
+
+ # GET /subscribers/1/edit
+ def edit
+ @subscriber = Subscriber.find(params[:id])
+ end
+
+ # POST /subscribers
+ # POST /subscribers.xml
+ def create
+ # look for subscriber with this email already
+ @skip_flash = true
+ found = Subscriber.find_by_address(params[:subscriber][:address])
+ if found
+ flash[:error] = "The email address \"#{params[:subscriber][:address]}\" has already been subscribed."
+ else
+ @subscriber = Subscriber.new(params[:subscriber])
+ if @subscriber.save
+ flash[:notice] = "You have been successfully subscribed."
+ else
+ @subscriber.errors.each do |attr_name,message|
+ attr_name = "email address" unless attr_name.to_s != "address"
+ flash[:error] = "I'm sorry, #{attr_name} #{message}"
+ end
+
+ end
+ end
+ redirect_to root_url
+
+ end
+
+ def destroy
+ #check to make sure the signature matches
+ if params[:signature] == sign_text(params[:id].to_s)
+ @subscriber = Subscriber.find(params[:id])
+ @subscriber.destroy
+ flash[:notice] = "#{@subscriber.address} has been successfully unsubscribed."
+ else
+ flash[:error] ="signatures did not match, please contact us if there was an error."
+ end
+ redirect_to root_url
+ end
+
+end
View
2 app/helpers/subscriber_helper.rb
@@ -0,0 +1,2 @@
+module SubscriberHelper
+end
View
2 app/helpers/subscribers_helper.rb
@@ -0,0 +1,2 @@
+module SubscribersHelper
+end
View
12 app/mailers/alert_mailer.rb
@@ -0,0 +1,12 @@
+class AlertMailer < ActionMailer::Base
+ default :from => "'The Stock Factor' <thestockfactor@gmail.com>"
+ layout 'email'
+ include Util
+ def top_changed_email(subscriber,symbol)
+ @signature = sign_text(subscriber.id.to_s)
+ @subscriber = subscriber
+ @symbol = symbol
+ mail(:to => subscriber.address,
+ :subject => "#{symbol} is now the symbol with the highest stock factor!")
+ end
+end
View
8 app/models/subscriber.rb
@@ -0,0 +1,8 @@
+class Subscriber < ActiveRecord::Base
+ attr_accessible :address
+ validates :address, :presence => true,
+ :length => {:minimum => 3, :maximum => 254},
+ :uniqueness => true,
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
+
+end
View
6 app/views/alert_mailer/top_changed_email.html.erb
@@ -0,0 +1,6 @@
+<%= @symbol %> is not the symbol with the highest stock factor.
+<br />
+<ul>
+ <li><%= link_to "See it on the graph",:only_path=>false,:host=>APP_CONFIG[:domain],:controller=>:entries,:action=>:symbol,:id=>@symbol %></li>
+ <li><a href="http://<%= APP_CONFIG[:domain] %>">See the list of the stocks with the highest factor</a> </li>
+</ul>
View
1 app/views/alert_mailer/top_changed_text.html.erb
@@ -0,0 +1 @@
+the symbol with the highest stock factor has changed
View
4 app/views/base/_flash.html.erb
@@ -0,0 +1,4 @@
+ <%- flash.each do |name, msg| -%>
+
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
View
17 app/views/entries/index.html.erb
@@ -9,6 +9,23 @@
<br/>
<hr>
<br/>
+ Want to be alerted when the stock with the highest factor changes? Enter your email below and we will send you
+ an email each time the top ones change. (Oh yeah, and we promise not to spam you or sell your email address.)
+ <div style="text-align:center"><% form_for @subscriber do |f| %>
+ <%= render :partial => "base/flash",:object => flash %>
+
+ <p>
+ <label>Email Address: </label>
+ <%= f.text_field :address,:id=>"tb" %>
+ <script>
+ var txtBox=document.getElementById("tb" );
+ if (txtBox!=null ) txtBox.focus();
+ </script>
+
+ <%= f.submit "Subscribe" %></p>
+ <% end %></div>
+
+ <hr>
</div>
View
4 app/views/layouts/application.html.erb
@@ -27,9 +27,7 @@
<body>
<div id="header"><span id="title"><a style="text-decoration:none;color:white" href="/">The Stock Factor</a></span><span class="title-link"><a target="_blank" href="https://twitter.com/thestockfactor">twitter</a><a href="mailto:thestockfactor@gmail.com">email us</a><span> </div>
<div id="container">
- <%- flash.each do |name, msg| -%>
- <%= content_tag :div, msg, :id => "flash_#{name}" %>
- <%- end -%>
+ <%= render :partial => "base/flash",:object => flash unless @flash_inner %>
<%- if show_title? -%>
<h1><%=h yield(:title) %></h1>
View
23 app/views/layouts/email.html.erb
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <table>
+ <tr>
+ <td>
+ <h3>The Stock Factor</h3>
+ </td>
+ </tr>
+ <tr>
+ <td><%= yield %></td>
+ </tr>
+ <tr>
+ <td>
+ <a href="<%= "http://#{APP_CONFIG[:domain]}/subscribers/destroy/#{@subscriber.id}?signature=#{@signature}"%>">Unsubscribe from all emails</a> (One click and you are unsubscribed, no confirm step.)
+ </td>
+ </tr>
+ </table>
+ </body>
+</html>
View
17 app/views/subscribers/_form.html.erb
@@ -0,0 +1,17 @@
+<%= form_for(@subscriber) do |f| %>
+ <% if @subscriber.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@subscriber.errors.count, "error") %> prohibited this subscriber from being saved:</h2>
+
+ <ul>
+ <% @subscriber.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/subscribers/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing subscriber</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @subscriber %> |
+<%= link_to 'Back', subscribers_path %>
View
21 app/views/subscribers/index.html.erb
@@ -0,0 +1,21 @@
+<h1>Listing subscribers</h1>
+
+<table>
+ <tr>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @subscribers.each do |subscriber| %>
+ <tr>
+ <td><%= link_to 'Show', subscriber %></td>
+ <td><%= link_to 'Edit', edit_subscriber_path(subscriber) %></td>
+ <td><%= link_to 'Destroy', subscriber, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Subscriber', new_subscriber_path %>
View
5 app/views/subscribers/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New subscriber</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', subscribers_path %>
View
5 app/views/subscribers/show.html.erb
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_subscriber_path(@subscriber) %> |
+<%= link_to 'Back', subscribers_path %>
View
3 config/application.rb
@@ -43,6 +43,9 @@ class Application < Rails::Application
# config.database_configuration_file= "/usr/local/pumpdump/conf/database.yml"
paths.config.database="/usr/local/pumpdump/conf/database.yml"
+ config.action_mailer.delivery_method = :ses
+
+
View
2 config/environments/development.rb
@@ -23,6 +23,8 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
+
+
puts "environment=development"
end
View
3 config/initializers/amazon_ses.rb
@@ -0,0 +1,3 @@
+ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
+ :access_key_id => APP_CONFIG[:aws_id],
+ :secret_access_key => APP_CONFIG[:aws_secret]
View
2 config/routes.rb
@@ -1,4 +1,6 @@
Pumpdump::Application.routes.draw do
+ resources :subscribers
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
12 db/migrate/20110225030804_add_emails_contacts.rb
@@ -0,0 +1,12 @@
+class AddEmailsContacts < ActiveRecord::Migration
+ def self.up
+ create_table :subscribers do |t|
+ t.timestamps
+ t.string(:address,:null=>false,:unique=>true)
+ end
+ end
+
+ def self.down
+ drop_table :subscribers
+ end
+end
View
9 db/migrate/20110226013757_add_index_on_subscriber_address.rb
@@ -0,0 +1,9 @@
+class AddIndexOnSubscriberAddress < ActiveRecord::Migration
+ def self.up
+ add_index(:subscribers,:address)
+ end
+
+ def self.down
+ remove_index(:subscribers,:address)
+ end
+end
View
10 db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101218192643) do
+ActiveRecord::Schema.define(:version => 20110226013757) do
create_table "bad_symbols", :force => true do |t|
t.string "symbol", :null => false
@@ -85,6 +85,14 @@
t.datetime "updated_at", :null => false
end
+ create_table "subscribers", :force => true do |t|
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "address", :null => false
+ end
+
+ add_index "subscribers", ["address"], :name => "index_subscribers_on_address"
+
create_table "tweets", :force => true do |t|
t.integer "source_id", :null => false
t.text "text", :null => false
View
22 lib/core.rb
@@ -118,10 +118,24 @@ def do_migrations
def top_changed(symbol)
# tweet it out
- response = HTTParty.post("http://easytweet.heroku.com/api/status",{:headers=>{"X-TWITTER-ID"=>APP_CONFIG[:easy_tweet_id].to_s,"X-TWITTER-TOKEN"=>APP_CONFIG[:easy_tweet_token].to_s},
- :body=>"The stock with the highest factor has changed to $#{symbol}. See it here http://thestockfactor.com"
- })
- Rails.logger.info("response from easy_tweet #{response.to_yaml}")
+ begin
+ response = HTTParty.post("http://easytweet.heroku.com/api/status", {:headers=>{"X-TWITTER-ID"=>APP_CONFIG[:easy_tweet_id].to_s, "X-TWITTER-TOKEN"=>APP_CONFIG[:easy_tweet_token].to_s},
+ :body=>"The stock with the highest factor has changed to $#{symbol}. See it here http://thestockfactor.com"
+ })
+ Rails.logger.info("response from easy_tweet #{response.to_yaml}")
+ rescue => e
+ Rails.logger.error(e)
+ end
+
+ Subscriber.all.each do |subscriber|
+ begin
+ Rails.logger.info("sending email to #{subscriber.to_yaml}")
+ AlertMailer.top_changed_email(subscriber, symbol).deliver()
+ rescue => e
+ Rails.logger.error(e)
+ end
+ end
+
end
View
12 lib/tasks/update.rake
@@ -98,6 +98,18 @@ namespace :update do
Rails.cache.write("top_symbol",nil)
end
+ task :set_top_changed => :environment do
+ Rails.cache.write("top_symbol","AAPL")
+ end
+
+ task :send_aws_email => :environment do
+ Subscriber.all.each do |subscriber|
+ Rails.logger.info("sending email to #{subscriber.to_yaml}")
+ AlertMailer.top_changed_email(subscriber, 'AAPL').deliver()
+ end
+
+ end
+
end
View
5 lib/util.rb
@@ -1,3 +1,4 @@
+require 'digest/md5'
module Util
# gets how many days ago it was, returns 0 if it was since the last market close
@@ -290,4 +291,8 @@ def do_with_pagination(model,query_args,page_size)
end
+ def sign_text(text)
+ Digest::MD5.hexdigest("#{text}#{APP_CONFIG[:provider_secret_key]}")
+ end
+
end
View
6 public/stylesheets/application.css
@@ -53,17 +53,17 @@ a {
padding-left: 16px;
}
-#flash_notice, #flash_error {
+#flash_notice, #flash_error, #flash_inner_error,#flash_inner_notice {
padding: 5px 8px;
margin: 10px 0;
}
-#flash_notice {
+#flash_notice,#flash_inner_notice {
background-color: #CFC;
border: solid 1px #6C6;
}
-#flash_error {
+#flash_error,#flash_inner_error {
background-color: #FCC;
border: solid 1px #C66;
}
View
56 public/stylesheets/scaffold.css
@@ -0,0 +1,56 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+
+#error_explanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+}
+
+#error_explanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
View
5 spec/controllers/subscriber_controller_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe SubscriberController do
+
+end
View
127 spec/controllers/subscribers_controller_spec.rb
@@ -0,0 +1,127 @@
+require 'spec_helper'
+
+describe SubscribersController do
+
+ def mock_subscriber(stubs={})
+ (@mock_subscriber ||= mock_model(Subscriber).as_null_object).tap do |subscriber|
+ subscriber.stub(stubs) unless stubs.empty?
+ end
+ end
+
+ describe "GET index" do
+ it "assigns all subscribers as @subscribers" do
+ Subscriber.stub(:all) { [mock_subscriber] }
+ get :index
+ assigns(:subscribers).should eq([mock_subscriber])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested subscriber as @subscriber" do
+ Subscriber.stub(:find).with("37") { mock_subscriber }
+ get :show, :id => "37"
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new subscriber as @subscriber" do
+ Subscriber.stub(:new) { mock_subscriber }
+ get :new
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested subscriber as @subscriber" do
+ Subscriber.stub(:find).with("37") { mock_subscriber }
+ get :edit, :id => "37"
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+ end
+
+ describe "POST create" do
+
+ describe "with valid params" do
+ it "assigns a newly created subscriber as @subscriber" do
+ Subscriber.stub(:new).with({'these' => 'params'}) { mock_subscriber(:save => true) }
+ post :create, :subscriber => {'these' => 'params'}
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+
+ it "redirects to the created subscriber" do
+ Subscriber.stub(:new) { mock_subscriber(:save => true) }
+ post :create, :subscriber => {}
+ response.should redirect_to(subscriber_url(mock_subscriber))
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved subscriber as @subscriber" do
+ Subscriber.stub(:new).with({'these' => 'params'}) { mock_subscriber(:save => false) }
+ post :create, :subscriber => {'these' => 'params'}
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+
+ it "re-renders the 'new' template" do
+ Subscriber.stub(:new) { mock_subscriber(:save => false) }
+ post :create, :subscriber => {}
+ response.should render_template("new")
+ end
+ end
+
+ end
+
+ describe "PUT update" do
+
+ describe "with valid params" do
+ it "updates the requested subscriber" do
+ Subscriber.should_receive(:find).with("37") { mock_subscriber }
+ mock_subscriber.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => "37", :subscriber => {'these' => 'params'}
+ end
+
+ it "assigns the requested subscriber as @subscriber" do
+ Subscriber.stub(:find) { mock_subscriber(:update_attributes => true) }
+ put :update, :id => "1"
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+
+ it "redirects to the subscriber" do
+ Subscriber.stub(:find) { mock_subscriber(:update_attributes => true) }
+ put :update, :id => "1"
+ response.should redirect_to(subscriber_url(mock_subscriber))
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the subscriber as @subscriber" do
+ Subscriber.stub(:find) { mock_subscriber(:update_attributes => false) }
+ put :update, :id => "1"
+ assigns(:subscriber).should be(mock_subscriber)
+ end
+
+ it "re-renders the 'edit' template" do
+ Subscriber.stub(:find) { mock_subscriber(:update_attributes => false) }
+ put :update, :id => "1"
+ response.should render_template("edit")
+ end
+ end
+
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested subscriber" do
+ Subscriber.should_receive(:find).with("37") { mock_subscriber }
+ mock_subscriber.should_receive(:destroy)
+ delete :destroy, :id => "37"
+ end
+
+ it "redirects to the subscribers list" do
+ Subscriber.stub(:find) { mock_subscriber }
+ delete :destroy, :id => "1"
+ response.should redirect_to(subscribers_url)
+ end
+ end
+
+end
View
15 spec/helpers/subscriber_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the SubscriberHelper. For example:
+#
+# describe SubscriberHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe SubscriberHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
15 spec/helpers/subscribers_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the SubscribersHelper. For example:
+#
+# describe SubscribersHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe SubscribersHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/mailers/alert_mailer_spec.rb
@@ -0,0 +1,5 @@
+require "spec_helper"
+
+describe AlertMailer do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/subscriber_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Subscriber do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
11 spec/requests/subscribers_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Subscribers" do
+ describe "GET /subscribers" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get subscribers_path
+ response.status.should be(200)
+ end
+ end
+end
View
35 spec/routing/subscribers_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe SubscribersController do
+ describe "routing" do
+
+ it "recognizes and generates #index" do
+ { :get => "/subscribers" }.should route_to(:controller => "subscribers", :action => "index")
+ end
+
+ it "recognizes and generates #new" do
+ { :get => "/subscribers/new" }.should route_to(:controller => "subscribers", :action => "new")
+ end
+
+ it "recognizes and generates #show" do
+ { :get => "/subscribers/1" }.should route_to(:controller => "subscribers", :action => "show", :id => "1")
+ end
+
+ it "recognizes and generates #edit" do
+ { :get => "/subscribers/1/edit" }.should route_to(:controller => "subscribers", :action => "edit", :id => "1")
+ end
+
+ it "recognizes and generates #create" do
+ { :post => "/subscribers" }.should route_to(:controller => "subscribers", :action => "create")
+ end
+
+ it "recognizes and generates #update" do
+ { :put => "/subscribers/1" }.should route_to(:controller => "subscribers", :action => "update", :id => "1")
+ end
+
+ it "recognizes and generates #destroy" do
+ { :delete => "/subscribers/1" }.should route_to(:controller => "subscribers", :action => "destroy", :id => "1")
+ end
+
+ end
+end
View
15 spec/views/subscribers/edit.html.erb_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "subscribers/edit.html.erb" do
+ before(:each) do
+ @subscriber = assign(:subscriber, stub_model(Subscriber))
+ end
+
+ it "renders the edit subscriber form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => subscriber_path(@subscriber), :method => "post" do
+ end
+ end
+end
View
14 spec/views/subscribers/index.html.erb_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe "subscribers/index.html.erb" do
+ before(:each) do
+ assign(:subscribers, [
+ stub_model(Subscriber),
+ stub_model(Subscriber)
+ ])
+ end
+
+ it "renders a list of subscribers" do
+ render
+ end
+end
View
15 spec/views/subscribers/new.html.erb_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "subscribers/new.html.erb" do
+ before(:each) do
+ assign(:subscriber, stub_model(Subscriber).as_new_record)
+ end
+
+ it "renders new subscriber form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => subscribers_path, :method => "post" do
+ end
+ end
+end
View
11 spec/views/subscribers/show.html.erb_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "subscribers/show.html.erb" do
+ before(:each) do
+ @subscriber = assign(:subscriber, stub_model(Subscriber))
+ end
+
+ it "renders attributes in <p>" do
+ render
+ end
+end

0 comments on commit efa0fcc

Please sign in to comment.
Something went wrong with that request. Please try again.