diff --git a/features/project/commits/commits.feature b/features/project/commits/commits.feature index cbe8b3215071c62cf55c49f1c4885db2fdb47fc8..7c6db3c465af1b375a15329ad45697260a74363e 100644 --- a/features/project/commits/commits.feature +++ b/features/project/commits/commits.feature @@ -38,10 +38,6 @@ Feature: Project Browse commits Given I visit big commit page Then I see big commit warning - Scenario: I browse huge commit - Given I visit huge commit page - Then I see huge commit message - Scenario: I browse a commit with an image Given I visit a commit with an image that changed Then The diff links to both the previous and current image diff --git a/features/project/commits/user_lookup.feature b/features/project/commits/user_lookup.feature index aa347e24fe49361b48bc6941a512b34a7ebb98b4..7b194ab9206b43298ada27c0adeefccc3133b877 100644 --- a/features/project/commits/user_lookup.feature +++ b/features/project/commits/user_lookup.feature @@ -2,13 +2,14 @@ Feature: Project Browse Commits User Lookup Background: Given I sign in as a user And I own a project - And I have the user that authored the commits And I visit my project's commits page Scenario: I browse commit from list - Given I click on commit link - Then I see commit info + Given I have user with primary email + When I click on commit link + Then I see author based on primary email Scenario: I browse another commit from list - Given I click on another commit link - Then I see other commit info + Given I have user with secondary email + When I click on another commit link + Then I see author based on secondary email diff --git a/features/steps/project/browse_commits.rb b/features/steps/project/browse_commits.rb index fe47a731915aba9a451688cd7258c192c29146a0..37207aafebe983bb5381f73fce411abd65a63d3f 100644 --- a/features/steps/project/browse_commits.rb +++ b/features/steps/project/browse_commits.rb @@ -2,11 +2,12 @@ class ProjectBrowseCommits < Spinach::FeatureSteps include SharedAuthentication include SharedProject include SharedPaths + include RepoHelpers Then 'I see project commits' do commit = @project.repository.commit page.should have_content(@project.name) - page.should have_content(commit.message) + page.should have_content(commit.message[0..20]) page.should have_content(commit.id.to_s[0..5]) end @@ -19,21 +20,21 @@ class ProjectBrowseCommits < Spinach::FeatureSteps page.response_headers['Content-Type'].should have_content("application/atom+xml") page.body.should have_selector("title", text: "Recent commits to #{@project.name}") page.body.should have_selector("author email", text: commit.author_email) - page.body.should have_selector("entry summary", text: commit.description) + page.body.should have_selector("entry summary", text: commit.description[0..10]) end Given 'I click on commit link' do - visit project_commit_path(@project, ValidCommit::ID) + visit project_commit_path(@project, sample_commit.id) end Then 'I see commit info' do - page.should have_content ValidCommit::MESSAGE - page.should have_content "Showing 1 changed file" + page.should have_content sample_commit.message + page.should have_content "Showing #{sample_commit.files_changed_count} changed files" end And 'I fill compare fields with refs' do - fill_in "from", with: "8716fc78f3c65bbf7bcf7b574febd583bc5d2812" - fill_in "to", with: "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" + fill_in "from", with: sample_commit.parent_id + fill_in "to", with: sample_commit.id click_button "Compare" end @@ -56,30 +57,24 @@ class ProjectBrowseCommits < Spinach::FeatureSteps end Given 'I visit big commit page' do - visit project_commit_path(@project, BigCommits::BIG_COMMIT_ID) + Commit::DIFF_SAFE_FILES = 20 + visit project_commit_path(@project, sample_big_commit.id) end Then 'I see big commit warning' do - page.should have_content BigCommits::BIG_COMMIT_MESSAGE + page.should have_content sample_big_commit.message page.should have_content "Too many changes" - end - - Given 'I visit huge commit page' do - visit project_commit_path(@project, BigCommits::HUGE_COMMIT_ID) - end - - Then 'I see huge commit message' do - page.should have_content BigCommits::HUGE_COMMIT_MESSAGE + Commit::DIFF_SAFE_FILES = 100 end Given 'I visit a commit with an image that changed' do - visit project_commit_path(@project, 'cc1ba255d6c5ffdce87a357ba7ccc397a4f4026b') + visit project_commit_path(@project, sample_image_commit.id) end Then 'The diff links to both the previous and current image' do links = page.all('.two-up span div a') - links[0]['href'].should =~ %r{blob/bc3735004cb45cec5e0e4fa92710897a910a5957} - links[1]['href'].should =~ %r{blob/cc1ba255d6c5ffdce87a357ba7ccc397a4f4026b} + links[0]['href'].should =~ %r{blob/#{sample_image_commit.old_blob_id}} + links[1]['href'].should =~ %r{blob/#{sample_image_commit.new_blob_id}} end Given 'I click side-by-side diff button' do @@ -93,5 +88,4 @@ class ProjectBrowseCommits < Spinach::FeatureSteps Then 'I see inline diff button' do page.should have_content "Inline Diff" end - end diff --git a/features/steps/project/browse_commits_user_lookup.rb b/features/steps/project/browse_commits_user_lookup.rb index 328be3735532bd583a93cd6afe686eacd05fdce1..198ea29f28d4de5bcf814c7cf6a509deee983c39 100644 --- a/features/steps/project/browse_commits_user_lookup.rb +++ b/features/steps/project/browse_commits_user_lookup.rb @@ -2,34 +2,47 @@ class ProjectBrowseCommitsUserLookup < Spinach::FeatureSteps include SharedAuthentication include SharedProject include SharedPaths - - Given 'I have the user that authored the commits' do - @user = create(:user, email: 'dmitriy.zaporozhets@gmail.com') - create(:email, { user: @user, email: 'dzaporozhets@sphereconsultinginc.com' }) - end Given 'I click on commit link' do - visit project_commit_path(@project, ValidCommit::ID) + visit project_commit_path(@project, sample_commit.id) end Given 'I click on another commit link' do - visit project_commit_path(@project, ValidCommitWithAltEmail::ID) + visit project_commit_path(@project, sample_commit.parent_id) + end + + step 'I have user with primary email' do + user_primary + end + + step 'I have user with secondary email' do + user_secondary end - Then 'I see commit info' do - page.should have_content ValidCommit::MESSAGE - check_author_link(ValidCommit::AUTHOR_EMAIL) + step 'I see author based on primary email' do + check_author_link(sample_commit.author_email, user_primary) end - - Then 'I see other commit info' do - page.should have_content ValidCommitWithAltEmail::MESSAGE - check_author_link(ValidCommitWithAltEmail::AUTHOR_EMAIL) + + step 'I see author based on secondary email' do + check_author_link(sample_commit.author_email, user_secondary) end - def check_author_link(email) + def check_author_link(email, user) author_link = find('.commit-author-link') - author_link['href'].should == user_path(@user) + author_link['href'].should == user_path(user) author_link['data-original-title'].should == email - find('.commit-author-name').text.should == @user.name + find('.commit-author-name').text.should == user.name + end + + def user_primary + @user_primary ||= create(:user, email: 'dmitriy.zaporozhets@gmail.com') + end + + def user_secondary + @user_secondary ||= begin + user = create(:user, email: 'dzaporozhets@example.com') + create(:email, { user: user, email: 'dmitriy.zaporozhets@gmail.com' }) + user + end end end diff --git a/features/steps/project/browse_files.rb b/features/steps/project/browse_files.rb index 1e54e00f37a874f275bb32dd5eb4c58e5b914ac1..6fd0c2c2ded5f08b1d1fb80b1bddbbc519282f1a 100644 --- a/features/steps/project/browse_files.rb +++ b/features/steps/project/browse_files.rb @@ -2,6 +2,7 @@ class ProjectBrowseFiles < Spinach::FeatureSteps include SharedAuthentication include SharedProject include SharedPaths + include RepoHelpers step 'I should see files from repository' do page.should have_content "VERSION" @@ -28,7 +29,7 @@ class ProjectBrowseFiles < Spinach::FeatureSteps end step 'I should see raw file content' do - page.source.should == ValidCommit::BLOB_FILE + page.source.should == sample_blob.data end step 'I click button "edit"' do diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb index 6acf877c2560a175557312fdedeb087373caffef..4e97dba20b392346b72c15e1795d5a4abc046c2d 100644 --- a/features/steps/shared/paths.rb +++ b/features/steps/shared/paths.rb @@ -1,5 +1,6 @@ module SharedPaths include Spinach::DSL + include RepoHelpers step 'I visit new project page' do visit new_project_path @@ -257,7 +258,7 @@ module SharedPaths end step 'I visit blob file from repo' do - visit project_blob_path(@project, File.join(ValidCommit::ID, ValidCommit::BLOB_FILE_PATH)) + visit project_blob_path(@project, File.join(sample_commit.id, sample_blob.path)) end step 'I visit ".gitignore" file in repo' do @@ -273,7 +274,7 @@ module SharedPaths end step 'I visit project commit page' do - visit project_commit_path(@project, ValidCommit::ID) + visit project_commit_path(@project, sample_commit.id) end step 'I visit project "Shop" issues page' do diff --git a/features/support/env.rb b/features/support/env.rb index 5b3e78cbec3397c923b63e8dade3d176fe1701e3..480cb361b67803ec84a64ac3c1c5d6870a5a0567 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -15,7 +15,7 @@ require 'spinach/capybara' require 'sidekiq/testing/inline' -%w(valid_commit valid_commit_with_alt_email big_commits select2_helper test_env).each do |f| +%w(select2_helper test_env repo_helpers).each do |f| require Rails.root.join('spec', 'support', f) end diff --git a/spec/support/big_commits.rb b/spec/support/big_commits.rb deleted file mode 100644 index 69daa709dd966515db234faef20908f90b9f1013..0000000000000000000000000000000000000000 --- a/spec/support/big_commits.rb +++ /dev/null @@ -1,8 +0,0 @@ -module BigCommits - HUGE_COMMIT_ID = "7f92534f767fa20357a11c63f973ae3b79cc5b85" - HUGE_COMMIT_MESSAGE = "pybments.rb version up. gitignore improved" - - BIG_COMMIT_ID = "d62200cad430565bd9f80befaf329297120330b5" - BIG_COMMIT_MESSAGE = "clean-up code" -end - diff --git a/spec/support/repo_helpers.rb b/spec/support/repo_helpers.rb new file mode 100644 index 0000000000000000000000000000000000000000..2584853077f42d26433d50ecc1c79e6234ae4ef0 --- /dev/null +++ b/spec/support/repo_helpers.rb @@ -0,0 +1,67 @@ +module RepoHelpers + extend self + + # Text file in repo + # + # Ex. + # + # # Get object + # blob = RepoHelpers.text_blob + # + # blob.path # => 'files/js/commit.js.coffee' + # blob.data # => 'class Commit...' + # + def sample_blob + OpenStruct.new( + path: "files/js/commit.js.coffee", + data: < + $('.files .diff-file').each -> + new CommitFile(this) + +@Commit = Commit +eos + ) + end + + def sample_commit + OpenStruct.new( + id: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d", + parent_id: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9', + author_full_name: "Dmitriy Zaporozhets", + author_email: "dmitriy.zaporozhets@gmail.com", + files_changed_count: 2, + message: < +eos + ) + end + + def sample_big_commit + OpenStruct.new( + id: "913c66a37b4a45b9769037c55c2d238bd0942d2e", + author_full_name: "Dmitriy Zaporozhets", + author_email: "dmitriy.zaporozhets@gmail.com", + message: < +eos + ) + end + + def sample_image_commit + OpenStruct.new( + id: "2f63565e7aac07bcdadb654e253078b727143ec4", + author_full_name: "Dmitriy Zaporozhets", + author_email: "dmitriy.zaporozhets@gmail.com", + old_blob_id: '33f3729a45c02fc67d00adb1b8bca394b0e761d9', + new_blob_id: '2f63565e7aac07bcdadb654e253078b727143ec4', + message: < +eos + ) + end +end diff --git a/spec/support/valid_commit.rb b/spec/support/valid_commit.rb deleted file mode 100644 index 65ad1d52084fd27efd06ecde716ed87d73943517..0000000000000000000000000000000000000000 --- a/spec/support/valid_commit.rb +++ /dev/null @@ -1,27 +0,0 @@ -module ValidCommit - ID = "570e7b2abdd848b95f2f578043fc23bd6f6fd24d" - MESSAGE = < -eos - AUTHOR_FULL_NAME = "Dmitriy Zaporozhets" - AUTHOR_EMAIL = "dmitriy.zaporozhets@gmail.com" - - FILES = [".foreman", ".gitignore", ".rails_footnotes", ".rspec", ".travis.yml", "CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "Procfile", "Procfile.production", "README.md", "Rakefile", "VERSION", "app", "config.ru", "config", "db", "doc", "lib", "log", "public", "resque.sh", "script", "spec", "vendor"] - FILES_COUNT = 26 - - C_FILE_PATH = "app/models" - C_FILES = [".gitkeep", "ability.rb", "commit.rb", "issue.rb", "key.rb", "mailer_observer.rb", "merge_request.rb", "note.rb", "project.rb", "protected_branch.rb", "repository.rb", "snippet.rb", "tree.rb", "user.rb", "users_project.rb", "web_hook.rb", "wiki.rb"] - - BLOB_FILE = < - $('.files .diff-file').each -> - new CommitFile(this) - -@Commit = Commit -eos - - BLOB_FILE_PATH = "files/js/commit.js.coffee" -end - diff --git a/spec/support/valid_commit_with_alt_email.rb b/spec/support/valid_commit_with_alt_email.rb deleted file mode 100644 index 75854c63a598a9b14544ba18e42fc0206fc99e39..0000000000000000000000000000000000000000 --- a/spec/support/valid_commit_with_alt_email.rb +++ /dev/null @@ -1,6 +0,0 @@ -module ValidCommitWithAltEmail - ID = "1e689bfba39525ead225eaf611948cfbe8ac34cf" - MESSAGE = "fixed notes logic" - AUTHOR_FULL_NAME = "Dmitriy Zaporozhets" - AUTHOR_EMAIL = "dzaporozhets@sphereconsultinginc.com" -end