require 'spec_helper' describe "Action Group" do it "should export: read groups of controller actions from yml and write in db" do simple_action_one = FactoryGirl.create(:extreme_simple_action, :controller_name => 'UsersController', :action_name => 'index') simple_action_two = FactoryGirl.create(:extreme_simple_action, :controller_name => 'UsersController', :action_name => 'show') action_group = {"dropbox" => [{"action_name" => "index", "controller_name" => 'UsersController'},{"action_name" => "show", "controller_name" => 'UsersController'}]} File.open("#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml", "w") do |out| YAML.dump action_group, out end ExtremeActionGroup.export "#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml" group = ExtremeActionGroup.last group.name.should == 'dropbox' group.actions.include?(simple_action_one.super_action).should be_true group.actions.include?(simple_action_two.super_action).should be_true end it "should export: read groups of helper methods from yml and write in db" do simple_action_one = FactoryGirl.create(:extreme_simple_action_helper, :helper_name => 'UsersHelper', :method_name => 'index') simple_action_two = FactoryGirl.create(:extreme_simple_action_helper, :helper_name => 'UsersHelper', :method_name => 'show') action_group = {"dropbox" => [{"method_name" => "index", "helper_name" => 'UsersHelper'},{"method_name" => "show", "helper_name" => 'UsersHelper'}]} File.open("#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml", "w") do |out| YAML.dump action_group, out end ExtremeActionGroup.export "#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml" group = ExtremeActionGroup.last group.name.should == 'dropbox' group.actions.include?(simple_action_one.super_action).should be_true group.actions.include?(simple_action_two.super_action).should be_true end it "should export: read groups of helper methods and controller actions from yml and write in db" do simple_action_one = FactoryGirl.create(:extreme_simple_action, :controller_name => 'UsersController', :action_name => 'index') simple_action_two = FactoryGirl.create(:extreme_simple_action_helper, :helper_name => 'UsersHelper', :method_name => 'show') action_group = {"dropbox" => [{"action_name" => "index", "controller_name" => 'UsersController'},{"method_name" => "show", "helper_name" => 'UsersHelper'}]} File.open("#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml", "w") do |out| YAML.dump action_group, out end ExtremeActionGroup.export "#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml" group = ExtremeActionGroup.last group.name.should == 'dropbox' group.actions.include?(simple_action_one.super_action).should be_true group.actions.include?(simple_action_two.super_action).should be_true end it "should export: read groups of groups" do simple_action_one = FactoryGirl.create(:extreme_simple_action, :controller_name => 'UsersController', :action_name => 'index') simple_action_two = FactoryGirl.create(:extreme_simple_action_helper, :helper_name => 'UsersHelper', :method_name => 'show') hash = {"group_child" => [{"action_name" => "index", "controller_name" => 'UsersController'}], "group_parent"=>[{"group"=>"group_child"},{"method_name" => "show", "helper_name" => 'UsersHelper'}]} File.open("#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml", "w") do |out| YAML.dump hash, out end ExtremeActionGroup.export "#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml" group_parent = ExtremeActionGroup.find_by_name "group_parent" group_child = ExtremeActionGroup.find_by_name "group_child" group_parent.actions.include?(group_child.super_action).should be_true group_parent.actions.include?(simple_action_two.super_action).should be_true end it "should export: read groups and sync with existing, without deleting non-volatile groups" do simple_action_one = FactoryGirl.create(:extreme_simple_action, :controller_name => 'UsersController', :action_name => 'index') simple_action_two = FactoryGirl.create(:extreme_simple_action_helper, :helper_name => 'UsersHelper', :method_name => 'show') hash = {"group_child" => [{"action_name" => "index", "controller_name" => 'UsersController'}], "group_parent"=>[{"group"=>"group_child"},{"method_name" => "show", "helper_name" => 'UsersHelper'}]} File.open("#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml", "w") do |out| YAML.dump hash, out end ExtremeActionGroup.export "#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml" ExtremeActionGroup.find_by_name("default").should_not be_nil end it "should export: read groups and sync with existing, with deleting volatile groups" do group = FactoryGirl.create(:extreme_action_group, :volatile => true) simple_action_one = FactoryGirl.create(:extreme_simple_action, :controller_name => 'UsersController', :action_name => 'index') simple_action_two = FactoryGirl.create(:extreme_simple_action_helper, :helper_name => 'UsersHelper', :method_name => 'show') hash = {"group_child" => [{"action_name" => "index", "controller_name" => 'UsersController'}], "group_parent"=>[{"group"=>"group_child"},{"method_name" => "show", "helper_name" => 'UsersHelper'}]} File.open("#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml", "w") do |out| YAML.dump hash, out end ExtremeActionGroup.export "#{ENGINE_RAILS_ROOT}/spec/support/extreme_aas_groups.yml" ExtremeActionGroup.find_by_name(group.name).should be_nil end end