diff --git a/Gemfile b/Gemfile index 2562fc9..9bab50d 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem 'sqlite3' gem 'turbolinks' gem 'uglifier', '>= 1.3.0' gem 'symmetric-encryption', '~> 3.8.1' +gem 'stripe' gem 'quiet_assets', group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 5381d6d..09c6a17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,7 +36,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.3.8) + addressable (2.4.0) arel (6.0.2) bcrypt (3.1.10) binding_of_caller (0.7.2) @@ -50,7 +50,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - childprocess (0.5.6) + childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) cliver (0.3.2) coderay (1.1.0) @@ -64,7 +64,7 @@ GEM execjs coffee-script-source (1.9.1.1) columnize (0.9.0) - cookiejar (0.3.2) + cookiejar (0.3.0) crack (0.4.2) safe_yaml (~> 1.0.0) database_cleaner (1.4.1) @@ -79,13 +79,15 @@ GEM thread_safe (~> 0.1) warden (~> 1.2.3) diff-lcs (1.2.5) - em-http-request (1.1.2) + domain_name (0.5.25) + unf (>= 0.0.5, < 1.0.0) + em-http-request (1.1.3) addressable (>= 2.3.4) - cookiejar + cookiejar (<= 0.3.0) em-socksify (>= 0.3) eventmachine (>= 1.0.3) http_parser.rb (>= 0.6.0) - em-socksify (0.3.0) + em-socksify (0.3.1) eventmachine (>= 1.0.0.beta.4) em-synchrony (1.0.4) eventmachine (>= 1.0.0.beta.1) @@ -93,7 +95,7 @@ GEM launchy (~> 2.1) mail (~> 2.2) erubis (2.7.0) - eventmachine (1.0.7) + eventmachine (1.0.9.1) eventmachine_httpserver (0.2.1) execjs (2.5.2) factory_girl (4.5.0) @@ -105,6 +107,8 @@ GEM globalid (0.3.5) activesupport (>= 4.1.0) hike (1.2.3) + http-cookie (1.0.2) + domain_name (~> 0.5) http_parser.rb (0.6.0) i18n (0.7.0) interception (0.5) @@ -124,6 +128,7 @@ GEM mini_portile (0.6.2) minitest (5.7.0) multi_json (1.11.2) + netrc (0.11.0) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) orm_adapter (0.5.0) @@ -144,11 +149,11 @@ GEM pry-stack_explorer (0.4.9.2) binding_of_caller (>= 0.7) pry (>= 0.9.11) - puffing-billy (0.5.1) + puffing-billy (0.6.2) addressable em-http-request (~> 1.1.0) em-synchrony - eventmachine + eventmachine (~> 1.0.4) eventmachine_httpserver http_parser.rb (~> 0.6.0) multi_json @@ -184,6 +189,10 @@ GEM rake (10.4.2) responders (2.1.0) railties (>= 4.2.0, < 5) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) rspec-core (3.3.2) rspec-support (~> 3.3.0) rspec-expectations (3.3.1) @@ -209,7 +218,7 @@ GEM sass (~> 3.2.2) sprockets (~> 2.8, < 3.0) sprockets-rails (~> 2.0) - selenium-webdriver (2.46.2) + selenium-webdriver (2.49.0) childprocess (~> 0.5) multi_json (~> 1.0) rubyzip (~> 1.0) @@ -230,6 +239,9 @@ GEM activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) sqlite3 (1.3.10) + stripe (1.34.0) + json (~> 1.8.1) + rest-client (~> 1.4) symmetric-encryption (3.8.1) coercible (~> 1.0) thor (0.19.1) @@ -242,6 +254,9 @@ GEM uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.1) vcr (2.9.3) warden (1.2.3) rack (>= 1.0) @@ -288,6 +303,7 @@ DEPENDENCIES spring spring-commands-rspec sqlite3 + stripe symmetric-encryption (~> 3.8.1) turbolinks uglifier (>= 1.3.0) diff --git a/README.md b/README.md index daef333..dc99754 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Hopefully this will be of help to those of you learning RSpec and Rails. If ther - [Routing Specs & Docs](#routing-specs--docs) - [Enable Spring for RSpec](#enable-spring-for-rspec) - [Automated Continuous Integration with Travis CI](#automated-continuous-integration-with-travis-ci) +- [Stripe](#stripe) - [Contributors](#contributors) @@ -168,10 +169,11 @@ Capybara configuration how-to and examples: If you need to debug Puffing Billy, refer to its output in `log/test.log`. Puffing Billy configuration how-to and examples: -- [spec/support/puffing_billy.rb](spec/support/puffing_billy.rb) +- [spec/support/puffing_billy.rb](spec/support/puffing_billy.rb) - see comments on recording responses with `RECORD` environment variable +- [spec/features/user_upgrades_spec.rb](spec/features/user_upgrades_spec.rb) - [spec/features/share_page_spec.rb](spec/features/share_page_spec.rb) - [Cache options](https://github.com/oesmith/puffing-billy#caching) -- [Cached responses in spec/support/http_cache/billy](spec/support/http_cache/billy) +- [Cached responses in spec/support/http_cache/browser](spec/support/http_cache/browser) # Shoulda-Matchers Examples @@ -311,6 +313,19 @@ Travis CI configuration how-to and example: - [Our Travis CI build!](https://travis-ci.org/eliotsykes/rspec-rails-examples) - Our Travis CI badge (hopefully its green): [![Build Status](https://travis-ci.org/eliotsykes/rspec-rails-examples.svg?branch=master)](https://travis-ci.org/eliotsykes/rspec-rails-examples) + +# Stripe + +The app uses Stripe to handle payments for users wishing to upgrade their membership from standard to premium. + +You can test Stripe's JavaScript integration without being dependent on Stripe's test environment network availability. For reliable, faster tests, its usually a good idea to make your tests work independently of any 3rd party environments. + +To remove the dependency on Stripe's environment, the test suite relies on Puffing Billy mocking the Stripe HTTP responses in the browser. + +- [spec/features/user_upgrades_spec.rb](spec/features/user_upgrades_spec.rb) +- [spec/support/http_cache/frontend/](spec/support/http_cache/frontend/) stores Stripe cached HTTP responses for Puffing Billy +- [Stripe testing guide](https://stripe.com/docs/testing) with card numbers for testing different error states + --- # Contributors diff --git a/app/models/user.rb b/app/models/user.rb index f010337..63f6ea2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,9 +5,27 @@ class User < ActiveRecord::Base :recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable + STANDARD = 'standard' + PREMIUM = 'premium' + ROLES = [STANDARD, PREMIUM].freeze + + validates_inclusion_of :role, in: ROLES + has_many :access_tokens, dependent: :destroy def issue_access_token access_tokens.create! end + + def upgradeable? + standard? + end + + def standard? + STANDARD == role + end + + def upgrade + update!(role: PREMIUM) + end end diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index a76228c..f3f26e1 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -3,6 +3,19 @@ <% if user_signed_in? %>

Hello, <%= current_user.email %>

+ + <%= form_tag "/charge" do %> + + <% end %> + <% else %>

Not registered? <%= link_to "Sign up", new_user_registration_path %>