diff --git a/Gemfile b/Gemfile index 1b6b5efd3..abcf5dd87 100644 --- a/Gemfile +++ b/Gemfile @@ -97,5 +97,5 @@ group :test do gem 'fuubar' gem 'diaspora-client', #:git => 'git@github.com:diaspora/diaspora-client.git' - :path => "~/work/diaspora-client" + :path => "~/workspace/diaspora-client" end diff --git a/Gemfile.lock b/Gemfile.lock index 943541489..c5dbe5c73 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT json (>= 1.2.4) PATH - remote: ~/work/diaspora-client + remote: ~/workspace/diaspora-client specs: diaspora-client (0.0.0) activerecord diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 37d558714..d9b46bf76 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -5,11 +5,14 @@ require 'uri' class AppConfig < Settingslogic - if Rails.env == 'test' - source File.join(Rails.root, "config", "application.yml.example") - else - source File.join(Rails.root, "config", "application.yml") + def self.source_file + if Rails.env == 'test' + File.join(Rails.root, "config", "application.yml.example") + else + File.join(Rails.root, "config", "application.yml") + end end + source source_file namespace Rails.env def self.load! diff --git a/spec/controllers/activity_streams/photos_controller_spec.rb b/spec/controllers/activity_streams/photos_controller_spec.rb index fdbe4ac94..8cbea264d 100644 --- a/spec/controllers/activity_streams/photos_controller_spec.rb +++ b/spec/controllers/activity_streams/photos_controller_spec.rb @@ -31,11 +31,10 @@ describe ActivityStreams::PhotosController do } JSON end - it 'allows token authentication' do - bob.reset_authentication_token! - get :create, @json.merge!(:auth_token => bob.authentication_token) + it 'allows oauth authentication' do + token = Factory(:oauth_access_token) + get :create, @json.merge!(:oauth_token => token.access_token) response.should be_success - warden.should be_authenticated end # It is unclear why this test fails. An equivalent cucumber feature passes in features/logs_in_and_out.feature. diff --git a/spec/factories.rb b/spec/factories.rb index 58d634c75..640fe1bdc 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -118,4 +118,15 @@ Factory.define(:app, :class => OAuth2::Provider.client_class) do |a| a.description "The best way to chub on the net." a.icon_url "/images/chubbies48.png" + a.permissions_overview "I will use the permissions this way!" + a.sequence(:public_key) {|n| OpenSSL::PKey::RSA.new(2048) } +end + +Factory.define(:oauth_authorization, :class => OAuth2::Provider.authorization_class) do |a| + a.association(:client, :factory => :app) + a.association(:resource_owner, :factory => :user) +end + +Factory.define(:oauth_access_token, :class => OAuth2::Provider.access_token_class) do |a| + a.association(:authorization, :factory => :oauth_authorization) end diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index 08a118b23..d9d579033 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -7,6 +7,7 @@ require 'spec_helper' require File.join(Rails.root, 'lib/webfinger') describe Webfinger do + let(:host_with_port) { "#{AppConfig.pod_uri.host}:#{AppConfig.pod_uri.port}" } let(:user1) { alice } let(:user2) { eve } @@ -40,19 +41,14 @@ describe Webfinger do context 'webfinger query chain processing' do describe '#webfinger_profile_url' do - it 'should parse out the webfinger template' do + it 'parses out the webfinger template' do finger.send(:webfinger_profile_url, diaspora_xrd).should == - "http://example.org/webfinger?q=foo@tom.joindiaspora.com" + "http://#{host_with_port}/webfinger?q=foo@tom.joindiaspora.com" end it 'should return nil if not an xrd' do finger.send(:webfinger_profile_url, '').should be nil end - - it 'should return the template for xrd' do - finger.send(:webfinger_profile_url, diaspora_xrd).should == - 'http://example.org/webfinger?q=foo@tom.joindiaspora.com' - end end describe '#xrd_url' do @@ -75,14 +71,17 @@ describe Webfinger do end end it 'should fetch a diaspora webfinger and make a person for them' do - diaspora_xrd.stub!(:body).and_return(diaspora_xrd) - hcard_xml.stub!(:body).and_return(hcard_xml) - diaspora_finger.stub!(:body).and_return(diaspora_finger) - RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) + User.delete_all; Person.delete_all; Profile.delete_all; + diaspora_xrd.should_receive(:body).and_return(diaspora_xrd) + hcard_xml.should_receive(:body).and_return(hcard_xml) + diaspora_finger.should_receive(:body).and_return(diaspora_finger) + RestClient.should_receive(:get).exactly(3).times.and_return(diaspora_xrd, diaspora_finger, hcard_xml) #new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") # http://tom.joindiaspora.com/.well-known/host-meta - f = Webfinger.new("alice@example.org").fetch + f = Webfinger.new("alice@#{host_with_port}").fetch + f.valid? + pp f.errors.full_messages f.should be_valid end diff --git a/spec/models/app_config_spec.rb b/spec/models/app_config_spec.rb index 9c0762059..37d32b6b5 100644 --- a/spec/models/app_config_spec.rb +++ b/spec/models/app_config_spec.rb @@ -40,13 +40,14 @@ describe AppConfig do context "when source config file (i.e. config/application.yml) does not exist" do before do - application_yml = File.join(Rails.root, "config", "application.yml") + application_yml = File.join(Rails.root, "config", "application.yml.example") @app_yml = File.join(Rails.root, "config", "app.yml") @app_config_yml = File.join(Rails.root, "config", "app_config.yml") File.should_receive(:exists?).with(application_yml).at_least(:once).and_return(false) end after do File.instance_eval { alias :exists? :obfuscated_by_rspec_mocks__exists? } # unmock exists? so that the AppConfig.reload! in the top-level after block can run + AppConfig.source(AppConfig.source_file) end context "and there are no old-style config files around" do it "prints an error message with instructions for setting up application.yml and exits" do diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index ef535b1ae..366895861 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -145,7 +145,7 @@ describe Profile do let(:profile) { Factory.build(:profile) } it 'accepts form data' do - profile.birthday.should == nil + profile.birthday = nil profile.date = { 'year' => '2000', 'month' => '01', 'day' => '01' } profile.birthday.year.should == 2000 profile.birthday.month.should == 1 @@ -166,8 +166,8 @@ describe Profile do profile.birthday.day.should == 1 end - it 'accepts blank initial vallues' do - profile.birthday.should == nil + it 'does not accept blank initial values' do + profile.birthday = nil profile.date = { 'year' => '2001', 'month' => '', 'day' => ''} profile.birthday.should == nil end