|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +module Refinery |
| 4 | + module Pages |
| 5 | + |
| 6 | + describe ".tabs" do |
| 7 | + after do |
| 8 | + Refinery::Pages.instance_eval { @tabs = [] } |
| 9 | + end |
| 10 | + |
| 11 | + it "returns an array of registered tabs" do |
| 12 | + rspec_tab = Refinery::Pages::Tab.register do |tab| |
| 13 | + tab.name = "rspec" |
| 14 | + tab.partial = "rspec" |
| 15 | + end |
| 16 | + |
| 17 | + Refinery::Pages.tabs.should include(rspec_tab) |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + describe ".tabs_for_template" do |
| 22 | + after do |
| 23 | + Refinery::Pages.instance_eval { @tabs = [] } |
| 24 | + end |
| 25 | + |
| 26 | + it "returns all tabs for which #templates hasn't been set" do |
| 27 | + rspec_tab = Refinery::Pages::Tab.register do |tab| |
| 28 | + tab.name = "rspec" |
| 29 | + tab.partial = "rspec" |
| 30 | + end |
| 31 | + |
| 32 | + Refinery::Pages.tabs_for_template("huh").should include(rspec_tab) |
| 33 | + end |
| 34 | + |
| 35 | + it "returns tabs with matched template" do |
| 36 | + rspec_tab = Refinery::Pages::Tab.register do |tab| |
| 37 | + tab.name = "rspec" |
| 38 | + tab.partial = "rspec" |
| 39 | + tab.templates = "rspec" |
| 40 | + end |
| 41 | + |
| 42 | + Refinery::Pages.tabs_for_template("rspec").should include(rspec_tab) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + describe Tab do |
| 47 | + after do |
| 48 | + Refinery::Pages.instance_eval { @tabs = [] } |
| 49 | + end |
| 50 | + |
| 51 | + describe ".register" do |
| 52 | + it "requires name to be set" do |
| 53 | + lambda { |
| 54 | + Refinery::Pages::Tab.register do |tab| |
| 55 | + tab.partial = "rspec" |
| 56 | + end |
| 57 | + }.should raise_error(/A tab MUST have a name!/) |
| 58 | + end |
| 59 | + |
| 60 | + it "requires partial to be set" do |
| 61 | + lambda { |
| 62 | + Refinery::Pages::Tab.register do |tab| |
| 63 | + tab.name = "rspec" |
| 64 | + end |
| 65 | + }.should raise_error(/A tab MUST have a partial!/) |
| 66 | + end |
| 67 | + |
| 68 | + it "sets #templates if it's not set" do |
| 69 | + rspec_tab = Refinery::Pages::Tab.register do |tab| |
| 70 | + tab.name = "rspec" |
| 71 | + tab.partial = "rspec" |
| 72 | + end |
| 73 | + |
| 74 | + rspec_tab.templates.should eq(["all"]) |
| 75 | + end |
| 76 | + |
| 77 | + it "converts #templates to array if it's not an array already" do |
| 78 | + rspec_tab = Refinery::Pages::Tab.register do |tab| |
| 79 | + tab.name = "rspec" |
| 80 | + tab.partial = "rspec" |
| 81 | + tab.templates = "rspec" |
| 82 | + end |
| 83 | + |
| 84 | + rspec_tab.templates.should eq(["rspec"]) |
| 85 | + end |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | +end |
0 commit comments