Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
caiohsramos authored and Anil Kumar Maurya committed Mar 25, 2021
1 parent 8622d3e commit baddd13
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
15 changes: 4 additions & 11 deletions spec/database.rb
Expand Up @@ -5,17 +5,10 @@
end
end

ActiveRecord::Migration.create_table "simple_new_dsls", :force => true do |t|
t.string "status"
end
ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t|
t.string "status"
end
ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t|
t.string "status"
end
ActiveRecord::Migration.create_table "users", :force => true do |t|
t.string "status"
%w(simple_new_dsls multiple_simple_new_dsls implemented_abstract_class_dsls users multiple_namespaceds).each do |table_name|
ActiveRecord::Migration.create_table table_name, :force => true do |t|
t.string "status"
end
end

ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
Expand Down
16 changes: 16 additions & 0 deletions spec/models/active_record/namespaced.rb
@@ -0,0 +1,16 @@
class MultipleNamespaced < ActiveRecord::Base
include AASM

aasm(:status, namespace: :car) do
state :unsold, initial: true
state :sold

event :sell do
transitions from: :unsold, to: :sold
end

event :return do
transitions from: :sold, to: :unsold
end
end
end
17 changes: 17 additions & 0 deletions spec/unit/persistence/active_record_persistence_multiple_spec.rb
Expand Up @@ -331,6 +331,23 @@
expect(MultipleSimpleNewDsl.unknown_scope).to contain_exactly(dsl2)
end
end

context "when namespeced" do
it "add namespaced scopes" do
expect(MultipleNamespaced).to respond_to(:car_unsold)
expect(MultipleNamespaced).to respond_to(:car_sold)

expect(MultipleNamespaced.car_unsold.is_a?(ActiveRecord::Relation)).to be_truthy
expect(MultipleNamespaced.car_sold.is_a?(ActiveRecord::Relation)).to be_truthy
end
it "add unnamespaced scopes" do
expect(MultipleNamespaced).to respond_to(:unsold)
expect(MultipleNamespaced).to respond_to(:sold)

expect(MultipleNamespaced.unsold.is_a?(ActiveRecord::Relation)).to be_truthy
expect(MultipleNamespaced.sold.is_a?(ActiveRecord::Relation)).to be_truthy
end
end
end # scopes

describe "direct assignment" do
Expand Down

0 comments on commit baddd13

Please sign in to comment.