Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 894 lines (755 sloc) 26.703 kb
55bfda4 Added A Rails template for a skeleton Facebook application.
Mark Daggett authored
1 # Facebook Skeleton App
2 # from Mark Daggett (http://www.locusfoc.us)
a552d81 asking the user what their canvas name is instead of forcing the user…
Mark Daggett authored
3 canvas_name = ask("What is your Facebook application's canvas name?")
4
55bfda4 Added A Rails template for a skeleton Facebook application.
Mark Daggett authored
5
6 # Plugins
7 plugin 'rspec', :git => 'git://github.com/dchelimsky/rspec.git'
8 plugin 'rspec-rails', :git => 'git://github.com/dchelimsky/rspec-rails.git'
9 plugin 'exception_notifier', :git => 'git://github.com/rails/exception_notification.git'
10 plugin 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git'
11
12 # Ignore auto-generated files
13 file '.gitignore',
14 %q{coverage/*
15 log/*.log
16 log/*.pid
17 db/*.db
18 db/*.sqlite3
19 db/schema.rb
20 tmp/**/*
21 .DS_Store
22 doc/api
23 doc/app
24 config/database.yml
25 public/javascripts/all.js
26 public/stylesheets/all.js
27 coverage/*
28 .dotest/*
29 }
30
31 # Initial Setup
32 generate("rspec")
33
34 # Initial Migration
35 file "db/migrate/20090129183012_initial_migration.rb",
36 %q{class InitialMigration < ActiveRecord::Migration
37 def self.up
38 create_table "accounts", :force => true do |t|
39 t.string "facebook_uid"
40 t.boolean "active"
41 t.boolean "is_app_user"
42 t.datetime "created_at"
43 t.datetime "updated_at"
44 end
45
46 create_table "sessions", :force => true do |t|
47 t.string "session_id", :null => false
48 t.text "data"
49 t.datetime "created_at"
50 t.datetime "updated_at"
51 end
52 execute("ALTER TABLE accounts CHANGE facebook_uid facebook_uid BIGINT") if adapter_name.to_s == "MySQL"
53 add_index "accounts", ["facebook_uid"], :name => "index_accounts_on_facebook_uid"
54
55 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
56 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
57 end
58
59 def self.down
60 drop_table :accounts
61 drop_table :sessions
62 end
63 end
64 }
65
66 rake "db:migrate"
67
68 # Now that we've migrated we can include Facebooker otherwise we get this error during the migration:
69 # uninitialized constant ActionController::AbstractRequest
70 # from: /vendor/plugins/facebooker/lib/facebooker/rails/facebook_url_rewriting.rb:2
71 plugin 'facebooker', :git => "git://github.com/mmangino/facebooker.git"
72 rake "facebooker:setup"
73
74 initializer 'mime_types.rb', %q{Mime::Type.register_alias 'text/html', :fbml}
75
76 # Prepare for distributed development
77 run "cp config/database.yml config/database.yml.example"
78
79
80 # Models
81 file 'app/models/account.rb',
82 %q{class Account < ActiveRecord::Base
83 named_scope :active, :conditions => { :active => true }
84
85 # Virtual attribute for when we need to associate a FB Session record with our model
86 attr_accessor :facebook_account
87
88 def to_param
89 facebook_uid.to_s
90 end
91
92 def uninstall
93 update_attributes(:active => false)
94 end
95
96 class <<self
97 def find_or_create_by_facebook_params(u)
98 account = find_or_initialize_by_facebook_uid(:is_app_user => true, :facebook_uid => u.uid.to_i, :active => true)
99 account.active = true
100 account.save
101 account
102 end
103 end
104 end
105 }
106
107 # Controllers
108 file 'app/controllers/application.rb',
109 %q{class ApplicationController < ActionController::Base
110 include FacebookerFilters
111 helper :all # include all helpers, all the time
112
113 # See ActionController::RequestForgeryProtection for details
114 # Uncomment the :secret if you're not using the cookie session store
115 protect_from_forgery :secret => 'CHANGE ME TO SOMETHING SECURE'
116
117 # For use with will_paginate calls
118 # For example: Account.paginate(:all, pagination_params.merge(:conditions => { :active => true }))
119
120 def pagination_params(opts = {})
121 { :page => params[:page] || 1, :per_page => params[:per_page] || 50 }.merge(opts)
122 end
123
124 # Redefine the needs permission method to include our redirect back to our app.
125 # This is to ensure we don't end up on a dead-end page on Facebook.
126 def application_needs_permission(perm)
127 redirect_to(facebook_session.permission_url(perm, :next => "http://apps.facebook.com/#{ENV['FACEBOOKER_RELATIVE_URL_ROOT']}"+request.request_uri))
128 end
129 end
130 }
131
132 file 'app/controllers/facebook_controller.rb',
133 %q{class FacebookController < ApplicationController
134 protect_from_forgery :except => [:index, :uninstalled, :authorized]
135 before_filter :only_for_facebook_users, :except => [:uninstalled]
136 before_filter :find_facebook_account_during_uninstall, :only => [:uninstalled]
137 before_filter :find_facebook_account, :except => [:uninstalled, :installed, :errors_with, :authorize_redirect, :authorized]
138
139 def index
140 redirect_to account_path(@account)
141 end
142
143 def authorized
144 end
145
146 def authorize_redirect
147 installed
148 end
149
150 def installed
151 @account = Account.find_or_create_by_facebook_params(facebook_session.user)
152 raise ActiveRecord::RecordNotFound unless @account
153 flash[:notice] = "The Facebook application is successfully installed."
154 index
155 end
156
157 def privacy
158 end
159
160 def uninstalled
161 find_facebook_account_during_uninstall
162 if @account.uninstall
163 render :nothing => true, :status => '200'
164 else
165 render :nothing => true, :status => '500'
166 end
167 end
168
169 def help
170 end
171 end
172 }
173
174 file 'app/controllers/accounts_controller.rb',
175 %q{class AccountsController < ApplicationController
176 before_filter :only_for_facebook_users
177 before_filter :find_facebook_account
178
179 # Used to view your own account
180 # GET /accounts
181 # GET /accounts.fbml
182 def index
183 respond_to do |format|
184 format.fbml # index.fbml.erb
185 end
186 end
187
188 # Used to view another user's account
189 # GET /show/1
190 # GET /show/1.fbml
191 def show
192 respond_to do |format|
193 format.fbml {} # show.fbml
194 end
195 end
196 end
197 }
198
199 # Helpers
200 file 'app/helpers/application_helper.rb',
201 %q{module ApplicationHelper
202
203 # Converts the normal Rails flash methods into the message types expected by Facebook.
204 def render_facebook_flash(custom_flash = nil)
205 message = custom_flash || flash
206 flash_types = [:notice, :warning]
207 message.keys.each do |x|
208 case x
209 when :notice
210 message[:success] = message[:notice]
211 when :warning
212 message[:explanation] = message[:warning]
213 end
214 end
215 flash_types = [:error, :explanation, :success]
216 flash_type = flash_types.detect { |a| message.keys.include?(a) }
217 "<fb:%s><fb:message>%s</fb:message></fb:%s>" % [flash_type.to_s, message[flash_type],flash_type.to_s] if flash_type
218 end
219 end}
220
221 # Stylesheets
222 file 'public/stylesheets/facebook_scaffold.css',
223 %q{/***************************************************
224 * Rails UI Elements
225 ***************************************************/
226 .flash_notice, .flash_error, .flash_warning, .flash_success, .flash_explanation {
227 border: 1px solid #ebdfb0;
228 background-color: #fff4c8;
229 padding-top:0.5em !important;
230 color: #000;
231 text-align: center;
232 }
233
234 .flash_error {
235 border: 1px solid #ebb0b0;
236 background-color: #ffc8c8;
237 }
238
239 .flash_notice, .flash_success {
240 border: 1px solid #b0ebb0;
241 background-color: #c8ffcb;
242 }
243
244 .flash_notice a, .flash_error a, .flash_warning a {
245 color: #01a163;
246 border: none !important;
247 }
248
249 .errorExplanation h2 {
250 margin: 0;
251 color: #c00;
252 }
253 .errorExplanation li {
254 margin-left: 3.0em;
255 font-weight: bolder;
256 list-style: decimal;
257 color: #c00;
258 }
259
260 .fieldWithErrors input {
261 background-color: #faa;
262 border: 1px solid #f00;
263 }
264 /***************************************************
265 * Facebook UI Elements
266 ***************************************************/
267 .fb_blue_button, .fb_gold_button {
268 display:block;
269 background-color: #536ea6;
270 padding:2px;
271 font-size:0.9em;
272 text-align:center;
273 color: #fff;
274 font-weight:bolder;
275 border: 1px solid #0e1f5b;
276 border-left: 1px solid #D8DFEA;
277 border-top: 1px solid #D8DFEA;
278 text-decoration:none;
279 }
280
281 .fb_gold_button {
282 background-color: #eff087;
283 border: 1px solid #DCDE32;
284 border-left: 1px solid #EFf087;
285 border-top: 1px solid #EFf087;
286 color: #1b1b1b;
287
288 }
289
290 .fb_content_box {
291 margin: 10px 0 0 0 !important;
292 border: 1px solid transparent;
293 border-top: 1px solid #3B5998;
294 }
295
296 .fb_content_box .fb_content_box {
297 border: none;
298 margin: 0 !important;
299 }
300
301 .fb_content_box .head {
302 background-color: #D8DFEA;
303 color: #3B5998;
304 font-size: 12px !important;
305 margin:0 !important;
306 padding:5px 5px 5px 10px !important;
307 font-weight:bolder !important;
308 }
309
310 .fb_content_box .fb_content_box .head {
311 background:#EEEEEE none repeat scroll 0% 0%;
312 }
313
314 .fb_content_box .sub_head {
315 background:#EEEEEE none repeat scroll 0% 0%;
316 margin:0 !important;
317 border-top:1px solid #CCCCCC;
318 color: #444444;
319 overflow:hidden;
320 padding:2px 5px 2px 10px !important;
321 font-size: 11px !important;
322 margin-bottom: 11px !important;
323 }
324
325 .fb_content_box .fb_content_box .sub_head {
326 background:#fff none repeat scroll 0% 0%;
327 }
328
329 .fb_content_box .sub_head .inline_list {
330 margin:0 !important;
331 }
332
333 .fb_content_box .sub_head .inline_list li {
334 padding-left: 5px !important;
335 font-size: 11px !important;
336 }
337
338 .fb_content_box .sub_head .inline_list li.first {
339 padding-left: 0 !important;
340 }
341
342 .fb_content_box .content {
343 padding:10px !important;
344 }
345
346 .inline_fb_button_list a {
347 display: block;
348 margin:0;
349 padding: 2px 10px;
350 color: #fff;
351 text-decoration: none;
352 }
353 .inline_fb_button_list a:hover, .inline_fb_button_list a:active {
354 background-color: #6d84B4;
355 }
356 .inline_fb_button_list {
357 display: block;
358 float: left;
359 font-size: 13px;
360 list-style-image: none;
361 list-style-position: outside;
362 list-style-type: none;
363 margin: 0px;
364 padding: 0px;
365 line-height: 2em;
366 text-align: left;
367 font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
368 font-size: 11px;
369 text-align: left;
370 }
371 .inline_fb_button_list li {
372 background-color: #3B5998;
373 display:block;
374 float:left;
375 font-weight:bold;
376 margin:0px 10px 0px 0px;
377 }
378 /***************************************************
379 * Pagination
380 ***************************************************/
381 .pagination {
382 padding: 3px !important;
383 margin: 3px !important;
384 }
385
386 .pagination a {
387 padding: 2px 5px 2px 5px;
388 margin: 2px;
389 border: 1px solid #3B5998;
390 text-decoration: none;
391 color: #3B5998;
392 background-color: transparent;
393 }
394
395 .pagination a:hover, .pagination a:active {
396 border: 1px solid #3B5998;
397 background-color: #3B5998;
398 color: #FFF;
399 font-weight: bold;
400 }
401
402 .pagination span.current {
403 padding: 2px 5px 2px 5px;
404 margin: 2px;
405 border: 1px solid #3B5998;
406 font-weight: bold;
407 background-color: #3B5998;
408 color: #FFF;
409 }
410
411 .pagination span.disabled {
412 padding: 2px 5px 2px 5px;
413 margin: 2px;
414 border: 1px solid #eee;
415 color: #ddd;
416 }
417 }
418
419 # Facebook Filters which are useful for sussing out and handling requests made by Facebook uers.
420 file 'lib/facebooker_filters.rb',
421 %q{# This module contains a collection of helper methods that make detecting and
422 # responding to Facebook methods easier.
423 module FacebookerFilters
424 def self.included(base)
425 base.class_eval do
426 # The is a conditional before_filter that will only fire for requests using the fbml format.
427 before_filter(:except => :uninstalled) do |controller|
428 if controller.params["format"].to_s == "fbml"
429
430 # This session property will be set if the user has called the allow_login_from_facebook is called before this
431 # filter; for example, prepend_before_filter :allow_login_from_facebook, :only => [:show]
432 if controller.session[:authenticate_through_facebook].nil? || controller.session[:authenticate_through_facebook] == false
433 controller.send(:ensure_application_is_installed_by_facebook_user)
434 end
435 end
436 end
437 end
438 end
439
440 def only_login_from_facebook_required
441 session[:authenticate_through_facebook] = true
442 end
443
444 # For requests that use .fbml
445 def find_facebook_account
446 @facebook_session = facebook_session
447 @account = Account.find_by_facebook_uid(@facebook_session.user.uid)
448
449 raise ActiveRecord::RecordNotFound unless @account
450 # Assign the current_account so that the existing before_filters that check for authentication can find this user.
451 # self.current_account = @account
452 @account
453 rescue ActiveRecord::RecordNotFound
454 flash[:error] = "Could Not Find Account"
455 redirect_to(installed_path(:format => 'fbml')) and return false
456 end
457
458 # Deny access to any request that does not use the fbml format.
459 def only_for_facebook_users
460 unless params['format'].to_s == "fbml"
461 flash[:error] = "This page must be viewed within Facebook."
462 redirect_to root_url and return false
463 end
464 end
465
466 def find_facebook_account_during_uninstall
467 @account = Account.find_by_facebook_uid(params["fb_sig_user"])
468 raise ActiveRecord::RecordNotFound unless @account
469 @account
470 rescue ActiveRecord::RecordNotFound
471 render :nothing => true, :status => '500' and return false
472 end
473 end
474 }
475
476 # Views
477 file 'app/views/layouts/application.fbml.erb',
478 %q{<% if ["production"].include?(ENV["RAILS_ENV"]) %>
479 <%= stylesheet_link_tag "facebook_scaffold", :media => "screen" %>
480 <%- else -%>
481 <%= content_tag :style, File.readlines("public/stylesheets/facebook_scaffold.css").join("\n"), :type=>'text/css' %>
482 <%- end -%>
483
484 <%= render_facebook_flash() %>
485
486 <%= yield %>
487
488 <%= content_tag :script, File.readlines("public/javascripts/application.js").join("\n") %>
489 }
490
491 file 'app/views/accounts/index.fbml.erb', %q{
492 Find me in: app/views/accounts/index.fbml.erb
493 }
494
495 file 'app/views/accounts/show.fbml.erb', %q{
496 Find me in: app/views/accounts/show.fbml.erb
497 }
498
499 file 'app/views/facebook/about.fbml.erb', %q{
500 Find me in: app/views/facebook/errors_with.fbml.erb
501 }
502
503 file 'app/views/facebook/tos.fbml.erb', %q{
504 Find me in: app/views/facebook/tos.fbml.erb
505 }
506
507 file 'app/views/facebook/errors_with.fbml.erb', %q{
508 Find me in: app/views/facebook/errors_with.fbml.erb
509 }
510
511 file 'app/views/facebook/help.fbml.erb', %q{
512 Find me in: app/views/facebook/help.fbml.erb
513 }
514
515 file 'app/views/facebook/index.fbml.erb', %q{
516 Find me in: app/views/facebook/index.fbml.erb
517 }
518
519 file 'app/views/facebook/installed.fbml.erb', %q{
520 Finde me in: app/views/facebook/installed.fbml.erb
521 }
522
523 # Rspec Tests
524
525 file 'spec/models/account_spec.rb',
526 %q{require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
527
528 describe Account do
529 fixtures :accounts
530 before(:each) do
531 @facebook_account = accounts(:new_facebook_user)
532 @valid_attributes = {
533 :facebook_uid => "123456",
534 :active => false
535 }
536 end
537
538 it "should create a new instance given valid attributes" do
539 lambda do
540 Account.create!(@valid_attributes)
541 end.should change(Account, :count).by(1)
542 end
543
544 it "should deactive the account" do
545 @facebook_account.uninstall.should == true
546 @facebook_account.reload.active.should == false
547 end
548 end
549 }
550
551 file 'spec/controllers/accounts_controller_spec.rb',
552 %q{require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
553
554 describe AccountsController do
555 describe "responding to GET index" do
556 it_should_behave_like "An installed Facebook Application"
557 it_should_behave_like "A valid Facebook session"
558 it_should_behave_like "An Account created through Facebook"
559
560 it "should expose all accounts as @accounts" do
561 get :index, :format => 'fbml'
562 response.should be_success
563 end
564 end
565 end
566 }
567
568 file 'spec/controllers/facebook_controller_spec.rb',
569 %q{require File.dirname(__FILE__) + '/../spec_helper'
570
571 describe FacebookController, "under a rest request from inside Facebook with the application installed" do
572 describe "handling GET /facebook.fbml" do
573 it_should_behave_like "An installed Facebook Application"
574 it_should_behave_like "A valid Facebook session"
575 it_should_behave_like "An Account created through Facebook"
576
577 def do_get
578 get :index, :format => 'fbml'
579 end
580
581 it "should redirect to errors page if facebook account cannot be found" do
582 Account.stub!(:find_by_facebook_uid).and_raise(ActiveRecord::RecordNotFound)
583 do_get
584 flash[:error].should == "Could Not Find Account"
585 end
586 end
587
588 describe "handling POST /facebook/installed.fbml" do
589 it_should_behave_like "An installed Facebook Application"
590 it_should_behave_like "A valid Facebook session"
591
592 def do_post
593 post :installed, :format => 'fbml'
594 end
595
596 it "should redirect to the index action" do
597 do_post
598 response.flash[:notice].should == "The Facebook application is successfully installed."
599 end
600 end
601
602 describe "handling POST /facebook/uninstalled.fbml" do
603 fixtures :accounts
604 it_should_behave_like "A valid Facebook session"
605
606 before(:each) do
607 @account = mock_account
608 end
609
610 def do_post
611 post :uninstalled, :format => 'fbml'
612 end
613
614 it "should deactivate a facebook account but not destroy the record" do
615 @account = accounts(:new_facebook_user)
616 Account.stub!(:find_by_facebook_uid).and_return(@account)
617 do_post
618 response.should be_success
619 @account.active.should == false
620 assigns[:account].id.should == @account.id
621 assigns[:account].active.should == false
622 end
623
624 it "should render an error if the uninstall fails" do
625 @account = accounts(:new_facebook_user)
626 @account.stub!(:uninstall).and_return(false)
627 Account.stub!(:find_by_facebook_uid).and_return(@account)
628 do_post
629 response.headers['Status'].should == '500'
630 response.should_not be_success
631 end
632
633 it "should render an error if the account cannot be found during uninstall" do
634 Account.stub!(:find_by_facebook_uid).and_raise(ActiveRecord::RecordNotFound)
635 do_post
636 response.headers['Status'].should == '500'
637 response.should_not be_success
638 end
639 end
640 end
641
642 describe FacebookController, "when accessing informational pages" do
643 it_should_behave_like "An installed Facebook Application"
644 it_should_behave_like "A valid Facebook session"
645 it_should_behave_like "An Account created through Facebook"
646
647 it "should display the about page" do
648 get :about, { :format => :fbml }
649 response.should be_success
650 response.body =~ /facebook\/about/
651 end
652
653 it "should display the help page" do
654 get :help, { :format => :fbml }
655 response.should be_success
656 response.body =~ /facebook\/help/
657 end
658
659 it "should display the privacy page" do
660 get :privacy, { :format => :fbml }
661 response.should be_success
662 response.body =~ /facebook\/privacy/
663 end
664 end
665
666 describe FacebookController, "under a rest request from outside of Facebook" do
667 describe "handling GET /facebook" do
668 it "should redirect you to the home url" do
669 get :index
670 response.flash[:error].should == "This page must be viewed within Facebook."
671 response.should redirect_to(root_url)
672 end
673 end
674 end
675 }
676
677 file 'spec/controllers/facebook_controller_routing_spec.rb',
678 %q{require File.dirname(__FILE__) + '/../spec_helper'
679 describe FacebookController do
680 describe "route generation" do
681 it "should map {:controller=>'facebook', :action=>'authorized'} to /authorized" do
682 route_for({:controller=>"facebook", :action=>"authorized"}).should == "/authorized"
683 end
684
685 it "should map {:controller=>'facebook', :action=>'authorize_redirect'} to /authorize_redirect" do
686 route_for({:controller=>"facebook", :action=>"authorize_redirect"}).should == "/authorize_redirect"
687 end
688
689 it "should map {:controller=>'facebook', :action=>'installed'} to /installed" do
690 route_for({:controller=>"facebook", :action=>"installed"}).should == "/installed"
691 end
692
693 it "should map {:controller=>'facebook', :action=>'privacy'} to /privacy" do
694 route_for({:controller=>"facebook", :action=>"privacy"}).should == "/privacy"
695 end
696
697 it "should map {:controller=>'facebook', :action=>'uninstalled'} to /uninstalled" do
698 route_for({:controller=>"facebook", :action=>"uninstalled"}).should == "/uninstalled"
699 end
700
701 it "should map {:controller=>'facebook', :action=>'help'} to /help" do
702 route_for({:controller=>"facebook", :action=>"help"}).should == "/help"
703 end
704 end
705
706 describe "route recognition" do
707 it "should generate params {:controller=>'facebook', :action=>'authorized'} from get /authorized" do
708 params_from(:get, "/authorized").should == {:controller=>'facebook', :action=>'authorized'}
709 end
710 it "should generate params {:controller=>'facebook', :action=>'authorized'} from get /authorize_redirect" do
711 params_from(:get, "/authorize_redirect").should == {:controller=>'facebook', :action=>'authorize_redirect'}
712 end
713 it "should generate params {:controller=>'facebook', :action=>'installed'} from get /installed" do
714 params_from(:get, "/installed").should == {:controller=>'facebook', :action=>'installed'}
715 end
716 it "should generate params {:controller=>'facebook', :action=>'privacy'} from get /privacy" do
717 params_from(:get, "/privacy").should == {:controller=>'facebook', :action=>'privacy'}
718 end
719 it "should generate params {:controller=>'facebook', :action=>'uninstalled'} from get /uninstalled" do
720 params_from(:get, "/uninstalled").should == {:controller=>'facebook', :action=>'uninstalled'}
721 end
722 it "should generate params {:controller=>'facebook', :action=>'help'} from get /help" do
723 params_from(:get, "/help").should == {:controller=>'facebook', :action=>'help'}
724 end
725 end
726 end
727 }
728
729 file 'spec/spec_helper.rb',
730 %q{ENV["RAILS_ENV"] = "test"
731 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
732 require 'spec'
733 require 'spec/rails'
734 require 'ruby-debug'
735
736 Spec::Runner.configure do |config|
737 # If you're not using ActiveRecord you should remove these
738 # lines, delete config/database.yml and disable :active_record
739 # in your config/boot.rb
740 config.use_transactional_fixtures = true
741 config.use_instantiated_fixtures = false
742 config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
743
744 module Spec
745 module Mocks
746 module Methods
747 def stub_association!(association_name, methods_to_be_stubbed = {})
748 mock_association = Spec::Mocks::Mock.new(association_name.to_s)
749 methods_to_be_stubbed.each do |method, return_value|
750 mock_association.stub!(method).and_return(return_value)
751 end
752 self.stub!(association_name).and_return(mock_association)
753 end
754 end
755 end
756 end
757
758 def mock_account(opts = {})
759 unless @account
760 @account = mock_model(Account, { :id => 1,
761 :facebook_uid => "123456789",
762 :active => true,
763 :update_attribute => true,
764 :update_attributes => true }.merge(opts))
765 end
766 @account
767 end
768
769 def mock_facebooker_session(opts = {})
770 mock_model(Facebooker::User, { :id => 1,
771 :first_name => 'Quentin',
772 :last_name => 'Jones',
773 :name => 'Quentin Jones',
774 :uid =>'987654321',
775 :profile_fbml= => true,
776 :is_app_user => true }.merge(opts))
777 end
778
779 describe "An installed Facebook Application", :shared => true do
780 before(:each) do
781 @controller.should_receive(:ensure_application_is_installed_by_facebook_user).at_least(:once).and_return(true)
782 end
783 end
784
785 describe "Logged into Facebook Application", :shared => true do
786 before(:each) do
787 @controller.should_receive(:ensure_authenticated_to_facebook).at_least(:once).and_return(true)
788 end
789 end
790
791 describe "An Installed Application With Extended Params", :shared => true do
792 before(:each) do
793 @controller.should_receive(:ensure_has_status_update).at_least(:once).and_return(true)
794 end
795 end
796
797 describe "An Account", :shared => true do
798 before(:each) do
799 Account.stub!(:find).and_return(mock_account)
800 end
801 end
802
803 describe "An Account created through Facebook", :shared => true do
804 before(:each) do
805 Account.stub!(:find_by_facebook_uid).and_return(mock_account)
806 end
807 end
808
809 describe "A valid Facebook session", :shared => true do
810 before(:each) do
811 @session = mock('fb_session',{ :user => mock_facebooker_session })
812 @controller.session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
813 @controller.stub!(:facebook_session).and_return(@session)
814 end
815 end
816 end
817 }
818
819 file 'spec/fixtures/accounts.yml',
820 %q{# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
821 new_facebook_user:
822 id: 1
823 facebook_uid: '12345678'
824 active: true
825 fb_user_two:
826 id: 2
827 facebook_uid: '2345456'
828 active: true
829 fb_user_three:
830 id: 3
831 facebook_uid: '345677'
832 active: true
833 }
834
835 # Routing
836 route "map.resources :accounts"
837
838 # Facebook specific routes.
839 # Canvas URL And Side Nav URL
840 # http://apps.facebook.com/FACEBOOK_APP_NAME/
841 route "map.root :controller => 'facebook'"
842
843 # About URL
844 # http://apps.facebook.com/FACEBOOK_APP_NAME/about
845 route "map.about '/about', :controller => 'facebook', :action => 'about'"
846
847 # Post-Authorize URL
848 # http://apps.facebook.com/FACEBOOK_APP_NAME/authorized
849 route "map.authorized '/authorized', :controller => 'facebook', :action => 'authorized'"
a552d81 asking the user what their canvas name is instead of forcing the user…
Mark Daggett authored
850 route "map.bp_authorized '/#{canvas_name}/authorized', :controller => 'facebook', :action => 'authorized'"
55bfda4 Added A Rails template for a skeleton Facebook application.
Mark Daggett authored
851
852 # Post-Authorize Redirect URL
853 # http://apps.facebook.com/FACEBOOK_APP_NAME/authorize_redirect
854 route "map.authorize_redirect '/authorize_redirect', :controller => 'facebook', :action => 'authorize_redirect'"
855
856 # Facebook Application Profile
857 # http://apps.facebook.com/FACEBOOK_APP_NAME/profile
858 route "map.authorize_redirect '/profile', :controller => 'accounts', :action => 'index'"
859
860 # Post-Add URL
861 # http://apps.facebook.com/FACEBOOK_APP_NAME/installed
862 route "map.installed '/installed', :controller => 'facebook', :action => 'installed'"
863
864 # Privacy URL
865 # http://apps.facebook.com/FACEBOOK_APP_NAME/privacy
866 route "map.privacy '/privacy', :controller => 'facebook', :action => 'privacy'"
867
868 # Terms Of Service
869 # http://apps.facebook.com/FACEBOOK_APP_NAME/tos
870 route "map.tos '/tos', :controller => 'facebook', :action => 'tos'"
871
872 # Post-Remove URL
873 # http://<some server>/FACEBOOK_APP_NAME/uninstalled
874 route "map.uninstalled '/uninstalled', :controller => 'facebook', :action => 'uninstalled'"
875
876 # Help URL
877 # http://apps.facebook.com/FACEBOOK_APP_NAME/help
878 route "map.help '/help', :controller => 'facebook', :action => 'help'"
879
880 # Errors
881 route "map.errors_with_facebook '/errors_with_facebook', :controller => 'facebook', :action => 'errors_with'"
882
883
884 # Finalize
885 run "rm README"
886 run "rm public/index.html"
887 run "rm public/favicon.ico"
888 run "rm public/robots.txt"
889
890
891 # Add the whole ball of wax to git
892 git :init
893 git :add => "."
894 git :commit => "-a -m 'Initial commit'"
Something went wrong with that request. Please try again.