diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 24599e243..c40b8cee8 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -14,7 +14,7 @@ class PullRequest < Issue end event :block do - transition [:open, :ready] => :block + transition [:open, :ready] => :blocked end event :merging do @@ -35,7 +35,7 @@ class PullRequest < Issue end def check - if ret = merge + if ret = merge #FIXME already up-to-date... system("cd #{path} && git reset --hard HEAD^") # remove merge commit ready else @@ -76,14 +76,11 @@ class PullRequest < Issue unless git.exist? FileUtils.mkdir_p(path) - Dir.chdir(path) do - system("git clone --local --no-hardlinks #{project.path} #{path}") - end - else - Dir.chdir(path) do - [data[:base_branch], data[:head_branch]].each do |branch| - system "git checkout #{branch} && git pull origin #{branch}" - end + system("git clone --local --no-hardlinks #{project.path} #{path}") + end + Dir.chdir(path) do + [data[:base_branch], data[:head_branch]].each do |branch| + system "git checkout #{branch} && git pull origin #{branch}" end end # TODO catch errors diff --git a/db/schema.rb b/db/schema.rb index 0b20e0d3a..7d911ec3d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,14 +17,14 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -33,8 +33,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -45,8 +45,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "version" end @@ -60,8 +60,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "project_id" t.integer "arch_id" t.datetime "notified_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -87,8 +87,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -102,8 +102,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.datetime "locked_at" t.datetime "failed_at" t.string "locked_by" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "queue", :default => "default" end @@ -121,14 +121,14 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -141,11 +141,14 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" + t.string "type" + t.string "state" + t.text "data", :default => "0", :null => false end add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true @@ -173,8 +176,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "description" t.string "name", :null => false t.integer "parent_platform_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "released", :default => false, :null => false t.integer "owner_id" t.string "owner_type" @@ -189,8 +192,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "user_id" end @@ -198,8 +201,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "product_id" t.integer "status", :default => 2, :null => false t.datetime "notified_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id" @@ -207,8 +210,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.text "build_script" t.text "counter" t.text "ks" @@ -227,8 +230,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "platform_id" end @@ -237,14 +240,14 @@ ActiveRecord::Schema.define(:version => 20120418100619) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" @@ -262,6 +265,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "build_count", :default => 0, :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false + create_table "register_requests", :force => true do |t| t.string "name" t.string "email" @@ -282,16 +287,16 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "object_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "name", :null => false end @@ -302,8 +307,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -312,8 +317,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -321,21 +326,21 @@ ActiveRecord::Schema.define(:version => 20120418100619) do create_table "users", :force => true do |t| t.string "name" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false t.string "reset_password_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.text "ssh_key" t.string "uname" t.string "role" - t.string "language", :default => "en" + t.string "language", :default => "en" + t.integer "own_projects_count", :default => 0, :null => false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.integer "own_projects_count", :default => 0, :null => false - t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company" @@ -344,7 +349,7 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" t.string "authentication_token" diff --git a/lib/tasks/reset_db.rake b/lib/tasks/reset_db.rake new file mode 100644 index 000000000..b3ebf98b2 --- /dev/null +++ b/lib/tasks/reset_db.rake @@ -0,0 +1,11 @@ +namespace :db do + desc "Drop, create, migrate then seed the database" + task :reset_db => :environment do + Rake::Task['db:drop'].invoke + Rake::Task['db:create'].invoke + Rake::Task['db:migrate'].invoke + Rake::Task['db:fixtures:load'].invoke + Rake::Task['db:seed'].invoke + end +end + diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index 3f4234648..4a1a4dd53 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -298,7 +298,8 @@ describe Comment do context 'for committer' do it 'should send an e-mail' do - @simple.update_attribute :email, 'code@tpope.net' + @simple.subscribes.destroy_all + @simple.update_attribute :email, 'test@test.test' comment = create_comment(@user) ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true @@ -306,21 +307,22 @@ describe Comment do it 'should send a one e-mail when subscribed to commit' do Subscribe.subscribe_to_commit @subscribe_params.merge(:user_id => @simple.id) - @simple.update_attribute :email, 'code@tpope.net' + @simple.update_attribute :email, 'test@test.test' comment = create_comment(@user) ActionMailer::Base.deliveries.count.should == 1 ActionMailer::Base.deliveries.last.to.include?(@simple.email).should == true end it 'should not send an e-mail for own comment' do - @simple.update_attribute :email, 'code@tpope.net' + @simple.subscribes.destroy_all + @simple.update_attribute :email, 'test@test.test' comment = create_comment(@simple) ActionMailer::Base.deliveries.count.should == 0 end it 'should not send an e-mail if global notify off' do @project.owner.notifier.update_attribute :can_notify, false - @simple.update_attribute :email, 'code@tpope.net' + @simple.update_attribute :email, 'test@test.test' @simple.notifier.update_attribute :can_notify, false comment = create_comment(@user) ActionMailer::Base.deliveries.count.should == 0 @@ -329,7 +331,7 @@ describe Comment do it 'should not send an e-mail if notify for my commits off' do Comment.destroy_all @simple.notifier.update_attribute :new_comment_commit_owner, false - @simple.update_attribute :email, 'code@tpope.net' + @simple.update_attribute :email, 'test@test.test' comment = create_comment(@user) ActionMailer::Base.deliveries.count.should == 0 end diff --git a/spec/models/pull_request_spec.rb b/spec/models/pull_request_spec.rb index 74d7791b1..80a2de044 100644 --- a/spec/models/pull_request_spec.rb +++ b/spec/models/pull_request_spec.rb @@ -1,21 +1,49 @@ # -*- encoding : utf-8 -*- require 'spec_helper' +def set_data_for_pull + @ability = Ability.new(@user) + + @project = FactoryGirl.create(:project, :owner => @user) + %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.path}) # maybe FIXME ? + + @clone_path = File.join(APP_CONFIG['root_path'], 'repo_clone', @project.id.to_s) + FileUtils.mkdir_p(@clone_path) + + + any_instance_of(Project, :versions => ['v1.0', 'v2.0']) +end + describe PullRequest do + context 'for owner user' do + before (:all) do + stub_rsync_methods + @user = FactoryGirl.create(:user) + set_data_for_pull + @pull = @project.pull_requests.new(:title => 'test', :body => 'testing') + @pull.user = @user + @pull.data = {:base_branch => 'master', :head_branch => 'non_conflicts'} + @pull.save + end - #~ context 'when create with same owner that platform' do - #~ before (:each) do - #~ stub_rsync_methods - #~ @platform = FactoryGirl.create(:platform) - #~ @params = {:name => 'tst_platform', :description => 'test platform'} - #~ end + it 'master should can be merged with non_conflicts branch' do + @pull.check + @pull.state.should == 'ready' + end + + it 'master should not be merged with conflicts branch' do + @pull.data[:head_branch] = 'conflicts' + @pull.check + @pull.state.should == 'blocked' + end + + it 'should not be merged when already up-to-date branches' do + @pull.data[:head_branch] = 'master' + @pull.check + @pull.state.should == 'blocked' # FIXME + end + end - #~ it 'it should increase Repository.count by 1' do - #~ rep = Repository.create(@params) {|r| r.platform = @platform} - #~ @platform.repositories.count.should eql(1) - #~ end - #~ end - before(:all) do stub_rsync_methods Platform.delete_all @@ -28,7 +56,7 @@ describe PullRequest do it { should belong_to(:project) } it { should have_many(:comments)} - + it { should validate_presence_of(:title)} #it { should validate_uniqueness_of(:serial_id).scoped_to(:project_id) } it { should validate_presence_of(:body) } diff --git a/spec/tests.git/HEAD b/spec/tests.git/HEAD index df9ee5473..cb089cd89 100644 --- a/spec/tests.git/HEAD +++ b/spec/tests.git/HEAD @@ -1 +1 @@ -bdc8b580b5b583aeb43efb19aac2ab8ce5566dff +ref: refs/heads/master diff --git a/spec/tests.git/config b/spec/tests.git/config index d38f8c6fe..07d359d07 100644 --- a/spec/tests.git/config +++ b/spec/tests.git/config @@ -1,11 +1,4 @@ [core] repositoryformatversion = 0 filemode = true - bare = false - logallrefupdates = true -[remote "origin"] - fetch = +refs/heads/*:refs/remotes/origin/* - url = git://github.com/tpope/vim-ragtag.git -[branch "master"] - remote = origin - merge = refs/heads/master + bare = true diff --git a/spec/tests.git/index b/spec/tests.git/index deleted file mode 100644 index 29cca27d4..000000000 Binary files a/spec/tests.git/index and /dev/null differ diff --git a/spec/tests.git/info/refs b/spec/tests.git/info/refs new file mode 100644 index 000000000..0e0a7c627 --- /dev/null +++ b/spec/tests.git/info/refs @@ -0,0 +1,5 @@ +5dc2326fab1022c9c35b27d09c62a73216fdff5e refs/heads/conficts +45d6bc11f4de8546ccbef16fdd3acf48fe0b411c refs/heads/conflicts +2babca2e12fe8e5f0ea95e8547a9ce20c322cb79 refs/heads/master +5c2312c4054bae9c1419dbec8633eda29f7c0731 refs/heads/non_conflicts +00a2f9225dcc5807b9eb46f1bcfc56ee939e595f refs/heads/not_conflicts diff --git a/spec/tests.git/logs/HEAD b/spec/tests.git/logs/HEAD deleted file mode 100644 index f47abecdc..000000000 --- a/spec/tests.git/logs/HEAD +++ /dev/null @@ -1,2 +0,0 @@ -0000000000000000000000000000000000000000 bdc8b580b5b583aeb43efb19aac2ab8ce5566dff Alexander 1325695134 +0600 clone: from git://github.com/tpope/vim-ragtag.git -bdc8b580b5b583aeb43efb19aac2ab8ce5566dff bdc8b580b5b583aeb43efb19aac2ab8ce5566dff Alexander 1325695134 +0600 checkout: moving from master to bdc8b580b5b583aeb43efb19aac2ab8ce5566dff diff --git a/spec/tests.git/logs/refs/heads/master b/spec/tests.git/logs/refs/heads/master deleted file mode 100644 index 9219de536..000000000 --- a/spec/tests.git/logs/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 bdc8b580b5b583aeb43efb19aac2ab8ce5566dff Alexander 1325695134 +0600 clone: from git://github.com/tpope/vim-ragtag.git diff --git a/spec/tests.git/objects/3b/efc54229f8e25165be593e67f33fb9a8495374 b/spec/tests.git/objects/3b/efc54229f8e25165be593e67f33fb9a8495374 new file mode 100644 index 000000000..e76437b56 --- /dev/null +++ b/spec/tests.git/objects/3b/efc54229f8e25165be593e67f33fb9a8495374 @@ -0,0 +1,2 @@ +xM +0a9L22I&E[im=g _]y@-\ZE+3C$+:M,(')=|!lD h3^C9\Ftpŀhп3-0~ \>y \ No newline at end of file diff --git a/spec/tests.git/objects/info/packs b/spec/tests.git/objects/info/packs new file mode 100644 index 000000000..870d85fea --- /dev/null +++ b/spec/tests.git/objects/info/packs @@ -0,0 +1,2 @@ +P pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.pack + diff --git a/spec/tests.git/objects/pack/pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.idx b/spec/tests.git/objects/pack/pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.idx new file mode 100644 index 000000000..6cf3769c5 Binary files /dev/null and b/spec/tests.git/objects/pack/pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.idx differ diff --git a/spec/tests.git/objects/pack/pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.pack b/spec/tests.git/objects/pack/pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.pack new file mode 100644 index 000000000..974873a7b Binary files /dev/null and b/spec/tests.git/objects/pack/pack-09ad35f874bea18d5f133a59210e4f80a1e81c17.pack differ diff --git a/spec/tests.git/objects/pack/pack-5185f74f028bf49d2611c9fea56570138a196143.idx b/spec/tests.git/objects/pack/pack-5185f74f028bf49d2611c9fea56570138a196143.idx deleted file mode 100644 index 46bd6036d..000000000 Binary files a/spec/tests.git/objects/pack/pack-5185f74f028bf49d2611c9fea56570138a196143.idx and /dev/null differ diff --git a/spec/tests.git/objects/pack/pack-5185f74f028bf49d2611c9fea56570138a196143.pack b/spec/tests.git/objects/pack/pack-5185f74f028bf49d2611c9fea56570138a196143.pack deleted file mode 100644 index 593982972..000000000 Binary files a/spec/tests.git/objects/pack/pack-5185f74f028bf49d2611c9fea56570138a196143.pack and /dev/null differ diff --git a/spec/tests.git/packed-refs b/spec/tests.git/packed-refs index b48a6248c..130291d58 100644 --- a/spec/tests.git/packed-refs +++ b/spec/tests.git/packed-refs @@ -1,5 +1,3 @@ -# pack-refs with: peeled -30aefeac002db3ec08ff278bd76290645469611e refs/tags/v2.0 -^644c62ad7bc7d9a4a5f19f5e8c41ef910782178b -235e4467107467feacc50553bbeda15e9bf99f57 refs/tags/v1.11 -bdc8b580b5b583aeb43efb19aac2ab8ce5566dff refs/remotes/origin/master +45d6bc11f4de8546ccbef16fdd3acf48fe0b411c refs/heads/conflicts +2babca2e12fe8e5f0ea95e8547a9ce20c322cb79 refs/heads/master +5c2312c4054bae9c1419dbec8633eda29f7c0731 refs/heads/non_conflicts diff --git a/spec/tests.git/refs/heads/master b/spec/tests.git/refs/heads/master deleted file mode 100644 index df9ee5473..000000000 --- a/spec/tests.git/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -bdc8b580b5b583aeb43efb19aac2ab8ce5566dff diff --git a/spec/tests.git/refs/remotes/origin/HEAD b/spec/tests.git/refs/remotes/origin/HEAD deleted file mode 100644 index 6efe28fff..000000000 --- a/spec/tests.git/refs/remotes/origin/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/remotes/origin/master