Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@linojon
Created September 20, 2009 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linojon/189670 to your computer and use it in GitHub Desktop.
Save linojon/189670 to your computer and use it in GitHub Desktop.
code snippets used in the SaasRamp screencast
# Some handy code snippets are used in the SaasRamp screencast (http://www.vaporbase.com/postings/SaasRamp_Screencast)
# File: environment.rb
config.gem 'activemerchant', :lib => 'active_merchant'
config.gem 'money'
config.gem 'state_machine'
config.gem 'lockfile'
config.active_record.observers = :subscription_observer
# File: environments/test.rb
config.gem "rspec", :lib => false, :version => ">= 1.2.0"
config.gem "rspec-rails", :lib => false, :version => ">= 1.2.0"
config.gem "mocha"
# File: app/models/user.rb
acts_as_subscriber
# File: spec/models/user_spec.rb
require File.dirname(__FILE__) + '/../../vendor/plugins/saasramp/spec/acts_as_subscriber_spec'
describe User do
before :each do
@subscriber = User.new( :username => 'username', :password => 'secret', :password_confirmation => 'secret', :email => 'a@example.com')
end
it_should_behave_like "a subscriber"
end
# File: spec/controllers/users_controller_spec.rb
before :each do
Subscription.any_instance.stubs(:plan).returns(SubscriptionPlan.default_plan)
end
# File: features/support/env.rb
# global subscription plans fixtures
# see http://wiki.github.com/aslakhellesoy/cucumber/fixtures
# and http://wiki.github.com/aslakhellesoy/cucumber/hooks
raw = File.read( RAILS_ROOT + '/db/subscription_plans.yml' )
data = YAML.load(raw)[RAILS_ENV].symbolize_keys
data[:plans].each {|params| SubscriptionPlan.create( params ) }
at_exit do
SubscriptionPlan.destroy_all
end
# alternative to save_and_open_page, see vaporbase...
def show_me
# remove: \ # ? & + = %2
name = response.request.request_uri.gsub('&','-').gsub(/[\/\#\?&\+\=(%2)]/,'-') +
"-#{Time.now.to_i}-#{rand(1_000_000)}"
File.open(RAILS_ROOT + "/public/cucumber/#{name}.html", "w"){ |f| f.puts response.body }
system "open -a Firefox.app http://localhost:3000/cucumber/#{name}.html"
end
# File: features/support/paths.rb
when /my profile/
edit_user_path(:current)
when /my subscription/
subscription_path(:current)
when /my plan/
edit_subscription_path(:current)
when /my credit card/
credit_card_subscription_path(:current)
# File: app/views/users/show.html.erb, insert line:
<%= render "sidebar" %>
# File: app/views/users/_sidebar.html.erb
<div class="sidebar">
<h2>Subscription</h2>
<p>
<strong>Plan:</strong>
<%= @user.subscription_plan.name.titleize %>
<span style="font-size:smaller">(<%= link_to "Change Plan", edit_subscription_path(:current) %>)</span>
</p>
<% unless @user.subscription.free? %>
<p>
<strong>Status:</strong>
<%= @user.subscription.state.titleize %>
</p>
<p>
<strong>Paid Through:</strong>
<%= @user.subscription.next_renewal_on %>
</p>
<% end %>
<p>
<%= button_to "Account Details", subscription_path(:current), :method => :get %>
</p>
</div>
# File: public/stylesheets/application.css, add
.sidebar {
float: right;
font-size: 12px;
background-color: #a88;
border: 2px solid #aaa;
padding: 1em;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment