Skip to content

Commit

Permalink
Add better test file management, and safer writes
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeese committed Nov 18, 2015
1 parent 0ff8320 commit cdf0205
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/avalon/controlled_vocabulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.vocabulary
# @param [Hash] vocabulary The new vocabulary to save
# @returns [Hash, false] The newly saved vocabulary, or false if save unable to obtain lock
def self.vocabulary= vocabulary
f = File.open(@@path, File::RDWR|File::CREAT, 0644)
f = File.open(@@path, File::RDWR|File::TRUNC|File::CREAT, 0644)
if f.flock(File::LOCK_NB|File::LOCK_EX)
YAML.dump(vocabulary, f)
f.flock(File::LOCK_UN)
Expand Down
11 changes: 9 additions & 2 deletions spec/controllers/vocabulary_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
# --- END LICENSE_HEADER BLOCK ---

require 'spec_helper'
require 'fileutils'

describe VocabularyController, type: :controller do
render_views

before(:each) { Avalon::ControlledVocabulary.class_variable_set :@@path, Rails.root.join('spec/fixtures/controlled_vocabulary.yml') }

before(:all) {
FileUtils.cp_r 'spec/fixtures/controlled_vocabulary.yml', 'spec/fixtures/controlled_vocabulary.yml.tmp'
Avalon::ControlledVocabulary.class_variable_set :@@path, Rails.root.join('spec/fixtures/controlled_vocabulary.yml.tmp')
}
after(:all) {
File.delete('spec/fixtures/controlled_vocabulary.yml.tmp')
}

describe "#index" do
it "should return vocabulary for entire app" do
get 'index'
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/controlled_vocabulary.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
:units:
- Default Unit
- New Unit
:identifier_types:
local: Catalog Key
oclc: OCLC
Expand Down

0 comments on commit cdf0205

Please sign in to comment.