-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class BundleContext < ApplicationRecord | ||
belongs_to :user | ||
|
||
validates :project_name, presence: true, null: false | ||
validates :content_structure, presence: true, null: false | ||
validates :bundle_dir, presence: true, null: false | ||
validates :staging_style_symlink, inclusion: { in: [ true, false ] } | ||
validates :content_metadata_creation, presence: true, null: false | ||
|
||
enum content_structure: { | ||
"simple_image_structure" => 0, | ||
"simple_book_structure" => 1, | ||
"book_as_iamge_structure" => 2, | ||
"file_structure" => 3, | ||
"smpl_structure" => 4 | ||
} | ||
|
||
enum content_metadata_creation: { | ||
"default_style" => 0, | ||
"filename_style" => 1, | ||
"smpl_style" => 2 | ||
} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class User < ApplicationRecord | ||
has_many :bundle_contexts | ||
validates :sunet_id, presence: true, uniqueness: true, null: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateBundleContexts < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :bundle_contexts do |t| | ||
t.string :project_name, null: false | ||
t.integer :content_structure, null: false | ||
t.string :bundle_dir, null: false | ||
t.boolean :staging_style_symlink, default: false, null: false | ||
t.integer :content_metadata_creation, null: false | ||
t.references :user, foreign_key: true, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
spec/lib/bundle_context_spec.rb → spec/lib/bundle_context_temporary_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe BundleContext, type: :model do | ||
context "validation" do | ||
let(:user) { User.new(sunet_id: "Jdoe")} | ||
subject(:bc) { BundleContext.new(project_name: "SmokeTest", | ||
content_structure: 1, | ||
bundle_dir: "spec/test_data/bundle_input_g", | ||
staging_style_symlink: false, | ||
content_metadata_creation: 1, | ||
user: user) } | ||
|
||
it "is not valid unless it has all required attributes" do | ||
expect(BundleContext.new).not_to be_valid | ||
expect(bc).to be_valid | ||
end | ||
|
||
context "defines enum with expected values" do | ||
it "content_structure enum" do | ||
is_expected.to define_enum_for(:content_structure).with( | ||
"simple_image_structure" => 0, | ||
"simple_book_structure" => 1, | ||
"book_as_iamge_structure" => 2, | ||
"file_structure" => 3, | ||
"smpl_structure" => 4 | ||
) | ||
end | ||
|
||
it "content_metadata_creation enum" do | ||
is_expected.to define_enum_for(:content_metadata_creation).with( | ||
"default_style" => 0, | ||
"filename_style" => 1, | ||
"smpl_style" => 2 | ||
) | ||
end | ||
end | ||
|
||
describe "#content_structure=" do | ||
it "validation rejects a value if it does not match the enum" do | ||
expect { described_class.new(content_structure: 654) } | ||
.to raise_error(ArgumentError, "'654' is not a valid content_structure") | ||
expect { described_class.new(content_structure: 'book_as_pdf') } | ||
.to raise_error(ArgumentError, "'book_as_pdf' is not a valid content_structure") | ||
end | ||
|
||
it "will accept a symbol, but will always return a string" do | ||
expect(described_class.new(content_structure: :smpl_structure).content_structure).to eq 'smpl_structure' | ||
end | ||
end | ||
|
||
describe "#content_metadata_creation=" do | ||
it "validation rejects a value if it does not match the enum" do | ||
expect { described_class.new(content_metadata_creation: 654) } | ||
.to raise_error(ArgumentError, "'654' is not a valid content_metadata_creation") | ||
expect { described_class.new(content_metadata_creation: 'dpg') } | ||
.to raise_error(ArgumentError, "'dpg' is not a valid content_metadata_creation") | ||
end | ||
|
||
it "will accept a symbol, but will always return a string" do | ||
expect(described_class.new(content_metadata_creation: :smpl_style).content_metadata_creation).to eq 'smpl_style' | ||
end | ||
end | ||
|
||
it { is_expected.to validate_presence_of(:project_name) } | ||
it { is_expected.to validate_presence_of(:content_structure) } | ||
it { is_expected.to validate_presence_of(:bundle_dir) } | ||
it { is_expected.to validate_presence_of(:content_metadata_creation) } | ||
it { is_expected.to belong_to(:user) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters