commit_spec.rb revision 81da36894af70bbb8d8e24b004026ad4c5c1bc99
2310N/Arequire 'spec_helper'
2310N/A
2310N/Adescribe Commit do
2310N/A context 'associations' do
2310N/A %i(ontology_versions ontologies).each do |association|
2310N/A it { should have_many(association) }
2310N/A end
2310N/A
2310N/A %i(repository author committer pusher).each do |association|
2310N/A it { should belong_to(association) }
2310N/A end
2310N/A end
2310N/A
2310N/A context 'saving a commit' do
2310N/A let(:repository) { create :repository }
2310N/A let(:pusher) { create :user }
2310N/A let(:file) { 'clif/Px.clif' }
2310N/A
2310N/A before do
2310N/A stub_hets_for(file)
2310N/A end
2310N/A
3158N/A context 'with author, committer and pusher being the same user' do
2310N/A let!(:commit_oid) do
3143N/A repository.save_file(ontology_file(file),
2310N/A File.basename(file), 'add file', pusher).commit_oid
2310N/A end
2310N/A let(:commit) { repository.commits.where(commit_oid: commit_oid).first }
2310N/A subject { commit }
2310N/A
2310N/A %i(author committer pusher).each do |field|
2310N/A it "saves the #{field}" do
2310N/A expect(subject.send(field)).to eq(pusher)
2310N/A end
2310N/A
3046N/A it "saves the #{field}_name" do
3046N/A expect(subject.send("#{field}_name")).to eq(pusher.name)
2310N/A end
2310N/A end
2310N/A
2310N/A %i(author committer).each do |field|
2310N/A it "saves the #{field}_email" do
2310N/A expect(subject.send("#{field}_email")).to eq(pusher.email)
2310N/A end
2310N/A end
2310N/A end
2310N/A
2310N/A context 'with different author, committer, pusher' do
2310N/A let(:author) { create :user }
2310N/A let(:committer) { create :user }
2310N/A let(:author_data) do
2310N/A {name: author.name, email: author.email, time: Time.now}
3171N/A end
3158N/A let(:committer_data) do
2310N/A {name: committer.name, email: committer.email, time: Time.now}
2310N/A end
2310N/A
2310N/A before do
2310N/A allow_any_instance_of(GitRepository).
2310N/A to receive(:commit_author).and_return(author_data)
2310N/A allow_any_instance_of(GitRepository).
2310N/A to receive(:commit_committer).and_return(committer_data)
2310N/A end
2310N/A
2310N/A let(:commit_oid) do
2310N/A repository.save_file(ontology_file(file),
2310N/A File.basename(file), 'add file', pusher).commit_oid
2310N/A end
2310N/A let(:commit) { repository.commits.where(commit_oid: commit_oid).first }
2310N/A subject { commit }
2310N/A
2310N/A it "saves the author's association" do
2310N/A expect(subject.author).to eq(author)
2310N/A end
3143N/A
2310N/A it "saves the author's name" do
3143N/A expect(subject.author_name).to eq(author.name)
2310N/A end
2310N/A
2310N/A it "saves the author's email" do
2310N/A expect(subject.author_email).to eq(author.email)
2310N/A end
2310N/A
2310N/A it "saves the committer's association" do
2310N/A expect(subject.committer).to eq(committer)
2310N/A end
2310N/A
2310N/A it "saves the committer's name" do
2310N/A expect(subject.committer_name).to eq(committer.name)
2310N/A end
2310N/A
2310N/A it "saves the committer's email" do
2310N/A expect(subject.committer_email).to eq(committer.email)
2310N/A end
2310N/A
2310N/A it "saves the pusher's association" do
2310N/A expect(subject.pusher).to eq(pusher)
2310N/A end
2310N/A
2310N/A it "saves the pusher's name" do
2310N/A expect(subject.pusher_name).to eq(pusher.name)
2310N/A end
2310N/A end
2310N/A end
2310N/Aend
2310N/A