require 'spec_helper' require 'fedux_org/stdlib/models/filesystem_based_model' describe Models::FilesystemBasedModel do before(:each) do @model = Class.new(Models::BaseModel) do include Models::FilesystemBasedModel def self.load_from_filesystem [ :hello, :world ].each { |s| create( s ) } end end @model.clear #where a name for a class is relevant module Test123 module Models class TestClassForFilesystem < FeduxOrg::Stdlib::Models::BaseModel include FeduxOrg::Stdlib::Models::FilesystemBasedModel end end end end it "returns a string of all active filters" do @model.create(:name1) @model.create(:name2) @model.enable :name1 @model.enable :name2 result = @model.all_names_as_string(", ") expect(result).to eq("name1, name2") result = @model.all_names_as_string expect(result).to eq("name1, name2") end it "finds all available filter" do @model.init filter = @model.find(:hello) expect(filter.name).to eq(:hello) end it "is default that all found filters are disabled" do @model.init all_filter = @model.all all_not_enabled_filter = @model.find_all(enabled: false) expect(all_filter.size).to eq(all_not_enabled_filter.size) end it "enables a filter by request" do @model.init @model.enable(:hello) all_enabled_filter = @model.find_all( enabled: true ) filter = @model.find( :hello ) expect( all_enabled_filter ).to eq( [ filter ] ) end it "s find method supports a hash based syntax" do @model.init @model.enable(:hello) enabled_filter = @model.find(name: :hello, enabled: true) expect(enabled_filter.name).to eq(:hello) end it "s find method supports a symbol based syntax as well. The search string is compared against the name method." do @model.init enabled_filter = @model.find(:hello) expect(enabled_filter.name).to eq(:hello) enabled_filter = @model.find_all(:hello) expect(enabled_filter.first.name).to eq(:hello) end it "s find method supports a string based syntax as well. The search string is compared against the name method." do @model.init enabled_filter = @model.find('hello') expect(enabled_filter.name).to eq(:hello) enabled_filter = @model.find_all('hello') expect(enabled_filter.first.name).to eq(:hello) end it "raises an error if an unknown search criteria is used" do @model.init expect { enabled_filter = @model.find(unknown: 'hello') }.to raise_error FeduxOrg::Stdlib::Models::Exceptions::InvalidSearchCriteria end it "returns the module name" do expect( Test123::Models::TestClassForFilesystem.send(:module_name) ).to eq('Test123::Models') end it "returns the model name" do expect( Test123::Models::TestClassForFilesystem.send(:model_name) ).to eq('TestClassForFilesystem') end it "returns the library name" do expect( Test123::Models::TestClassForFilesystem.send(:library_name) ).to eq('Test123') end end