Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:travis-ci/travis-core
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Jul 13, 2012
2 parents db2df82 + c91a8d7 commit 3dc56d4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions db/migrate/20120713153215_rename_in_sync_to_is_syncing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameInSyncToIsSyncing < ActiveRecord::Migration
def change
rename_column :users, :in_sync, :is_syncing
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120713140816) do
ActiveRecord::Schema.define(:version => 20120713153215) do

create_table "artifacts", :force => true do |t|
t.text "content"
Expand Down Expand Up @@ -199,7 +199,7 @@
t.string "github_oauth_token"
t.string "gravatar_id"
t.string "locale"
t.boolean "in_sync"
t.boolean "is_syncing"
t.datetime "synced_at"
end

Expand Down
15 changes: 14 additions & 1 deletion lib/travis/model/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ def find_or_create_for_oauth(payload)
end

def sync
Travis::Github::Sync::User.new(self).run
syncing { Travis::Github::Sync::User.new(self).run }
end

def syncing
update_attribute :is_syncing, true
result = yield
update_attribute :synced_at, Time.now
result
ensure
update_attribute :is_syncing, false
end

def syncing?
is_syncing?
end

def organization_ids
Expand Down
18 changes: 18 additions & 0 deletions spec/travis/model/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,22 @@ def user(payload)
service_hooks.any? { |s| s.name == 'other-repo' }.should be_false
end
end

describe 'syncing' do
it 'returns the block value' do
user.syncing { 42 }.should == 42
end

it 'sets is_syncing?' do
user.should_not be_syncing
user.syncing { user.should be_syncing }
user.should_not be_syncing
end

it 'sets synced_at' do
time = Time.now
user.syncing { }
user.synced_at.should >= time
end
end
end

0 comments on commit 3dc56d4

Please sign in to comment.