prismic.io 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/prismic.rb +20 -29
- data/lib/prismic/api.rb +7 -8
- data/lib/prismic/fragments/group.rb +17 -0
- data/lib/prismic/fragments/link.rb +11 -3
- data/lib/prismic/json_parsers.rb +16 -5
- data/lib/prismic/version.rb +1 -1
- data/lib/prismic/with_fragments.rb +28 -6
- data/prismic.gemspec +10 -10
- data/spec/doc_spec.rb +15 -15
- data/spec/fragments_spec.rb +3 -1
- data/spec/lesbonneschoses_spec.rb +46 -35
- data/spec/prismic_spec.rb +86 -162
- data/spec/responses_mocks/api.json +12 -12
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
    
        data/spec/fragments_spec.rb
    CHANGED
    
    | @@ -48,7 +48,7 @@ end | |
| 48 48 |  | 
| 49 49 | 
             
            describe 'DocumentLink' do
         | 
| 50 50 | 
             
              before do
         | 
| 51 | 
            -
                @document_link = Prismic::Fragments::DocumentLink.new("UdUjvt_mqVNObPeO", "product", ["Macaron"], "dark-chocolate-macaron", false)
         | 
| 51 | 
            +
                @document_link = Prismic::Fragments::DocumentLink.new("UdUjvt_mqVNObPeO", nil, "product", ["Macaron"], "dark-chocolate-macaron", {}, false)
         | 
| 52 52 | 
             
              end
         | 
| 53 53 |  | 
| 54 54 | 
             
              describe 'url' do
         | 
| @@ -623,9 +623,11 @@ describe 'StructuredText::Hyperlink' do | |
| 623 623 | 
             
              before do
         | 
| 624 624 | 
             
                @link = Prismic::Fragments::DocumentLink.new(
         | 
| 625 625 | 
             
                  "UdUjvt_mqVNObPeO",
         | 
| 626 | 
            +
                  nil,
         | 
| 626 627 | 
             
                  "product",
         | 
| 627 628 | 
             
                  ["Macaron"],
         | 
| 628 629 | 
             
                  "dark-chocolate-macaron",
         | 
| 630 | 
            +
                  {},
         | 
| 629 631 | 
             
                  false  # not broken
         | 
| 630 632 | 
             
                )
         | 
| 631 633 | 
             
                @hyperlink = Prismic::Fragments::StructuredText::Span::Hyperlink.new(0, 0, @link)
         | 
| @@ -3,7 +3,7 @@ require 'spec_helper' | |
| 3 3 |  | 
| 4 4 | 
             
            describe 'LesBonnesChoses' do
         | 
| 5 5 | 
             
              before do
         | 
| 6 | 
            -
                @api = Prismic.api('https://lesbonneschoses.prismic.io/api', nil)
         | 
| 6 | 
            +
                @api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api', nil)
         | 
| 7 7 | 
             
                @master_ref = @api.master_ref
         | 
| 8 8 | 
             
              end
         | 
| 9 9 |  | 
| @@ -19,86 +19,86 @@ describe 'LesBonnesChoses' do | |
| 19 19 | 
             
                  @api.form('everything').submit(@master_ref).results.size.should == 20
         | 
| 20 20 | 
             
                end
         | 
| 21 21 |  | 
| 22 | 
            -
                it  | 
| 23 | 
            -
                  @api.form( | 
| 24 | 
            -
                    .query( | 
| 22 | 
            +
                it 'queries macarons (using a predicate) and returns 7 documents' do
         | 
| 23 | 
            +
                  @api.form('everything')
         | 
| 24 | 
            +
                    .query('[[:d = any(document.tags, ["Macaron"])]]')
         | 
| 25 25 | 
             
                    .submit(@master_ref).results.size.should == 7
         | 
| 26 | 
            -
                  @api.form( | 
| 27 | 
            -
                    .query( | 
| 26 | 
            +
                  @api.form('everything')
         | 
| 27 | 
            +
                    .query('[[:d = any(document.tags, ["Macaron"])]]')
         | 
| 28 28 | 
             
                    .submit(@master_ref).size.should == 7
         | 
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| 31 | 
            -
                it  | 
| 32 | 
            -
                  @api.form( | 
| 33 | 
            -
                  @api.form( | 
| 31 | 
            +
                it 'queries macarons (using a form) and returns 7 documents' do
         | 
| 32 | 
            +
                  @api.form('macarons').submit(@master_ref).results.size.should == 7
         | 
| 33 | 
            +
                  @api.form('macarons').submit(@master_ref).size.should == 7
         | 
| 34 34 | 
             
                end
         | 
| 35 35 |  | 
| 36 | 
            -
                it  | 
| 37 | 
            -
                  @api.form( | 
| 38 | 
            -
                    .query( | 
| 36 | 
            +
                it 'queries macarons or cupcakes (using a form + a predicate) and returns 11 documents' do
         | 
| 37 | 
            +
                  @api.form('products')
         | 
| 38 | 
            +
                    .query('[[:d = any(document.tags, ["Cupcake", "Macaron"])]]')
         | 
| 39 39 | 
             
                    .submit(@master_ref).results.size.should == 11
         | 
| 40 | 
            -
                  @api.form( | 
| 41 | 
            -
                    .query( | 
| 40 | 
            +
                  @api.form('products')
         | 
| 41 | 
            +
                    .query('[[:d = any(document.tags, ["Cupcake", "Macaron"])]]')
         | 
| 42 42 | 
             
                    .submit(@master_ref).size.should == 11
         | 
| 43 43 | 
             
                end
         | 
| 44 44 | 
             
              end
         | 
| 45 45 |  | 
| 46 46 | 
             
              describe 'pagination' do
         | 
| 47 | 
            -
                it  | 
| 48 | 
            -
                  documents = @api.form( | 
| 47 | 
            +
                it 'works in basic cases' do
         | 
| 48 | 
            +
                  documents = @api.form('everything').submit(@master_ref)
         | 
| 49 49 | 
             
                  documents.page.should == 1
         | 
| 50 50 | 
             
                  documents.results_per_page.should == 20
         | 
| 51 51 | 
             
                  documents.results_size.should == 20
         | 
| 52 52 | 
             
                  documents.total_results_size.should == 40
         | 
| 53 53 | 
             
                  documents.total_pages.should == 2
         | 
| 54 | 
            -
                  documents.next_page.should ==  | 
| 54 | 
            +
                  documents.next_page.should == 'https://lesbonneschoses.cdn.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=20'
         | 
| 55 55 | 
             
                  documents.prev_page.should == nil
         | 
| 56 56 | 
             
                end
         | 
| 57 | 
            -
                it  | 
| 58 | 
            -
                  documents = @api.form( | 
| 57 | 
            +
                it 'works when passing nil' do
         | 
| 58 | 
            +
                  documents = @api.form('everything').page(nil).submit(@master_ref)
         | 
| 59 59 | 
             
                  documents.page.should == 1
         | 
| 60 60 | 
             
                  documents.results_per_page.should == 20
         | 
| 61 61 | 
             
                  documents.results_size.should == 20
         | 
| 62 62 | 
             
                  documents.total_results_size.should == 40
         | 
| 63 63 | 
             
                  documents.total_pages.should == 2
         | 
| 64 | 
            -
                  documents.next_page.should ==  | 
| 64 | 
            +
                  documents.next_page.should == 'https://lesbonneschoses.cdn.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=20'
         | 
| 65 65 | 
             
                  documents.prev_page.should == nil
         | 
| 66 66 | 
             
                end
         | 
| 67 | 
            -
                it  | 
| 68 | 
            -
                  documents = @api.form( | 
| 67 | 
            +
                it 'works on page 2' do
         | 
| 68 | 
            +
                  documents = @api.form('everything').page("2").submit(@master_ref)
         | 
| 69 69 | 
             
                  documents.page.should == 2
         | 
| 70 70 | 
             
                  documents.results_per_page.should == 20
         | 
| 71 71 | 
             
                  documents.results_size.should == 20
         | 
| 72 72 | 
             
                  documents.total_results_size.should == 40
         | 
| 73 73 | 
             
                  documents.total_pages.should == 2
         | 
| 74 74 | 
             
                  documents.next_page.should == nil
         | 
| 75 | 
            -
                  documents.prev_page.should ==  | 
| 75 | 
            +
                  documents.prev_page.should == 'https://lesbonneschoses.cdn.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=1&pageSize=20'
         | 
| 76 76 | 
             
                end
         | 
| 77 | 
            -
                it  | 
| 78 | 
            -
                  documents = @api.form( | 
| 77 | 
            +
                it 'works on page 2 with a pagination step of 10' do
         | 
| 78 | 
            +
                  documents = @api.form('everything').page('2').page_size('10').submit(@master_ref)
         | 
| 79 79 | 
             
                  documents.page.should == 2
         | 
| 80 80 | 
             
                  documents.results_per_page.should == 10
         | 
| 81 81 | 
             
                  documents.results_size.should == 10
         | 
| 82 82 | 
             
                  documents.total_results_size.should == 40
         | 
| 83 83 | 
             
                  documents.total_pages.should == 4
         | 
| 84 | 
            -
                  documents.next_page.should ==  | 
| 85 | 
            -
                  documents.prev_page.should ==  | 
| 84 | 
            +
                  documents.next_page.should == 'https://lesbonneschoses.cdn.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=3&pageSize=10'
         | 
| 85 | 
            +
                  documents.prev_page.should == 'https://lesbonneschoses.cdn.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=1&pageSize=10'
         | 
| 86 86 | 
             
                end
         | 
| 87 | 
            -
                it  | 
| 88 | 
            -
                  documents = @api.form( | 
| 87 | 
            +
                it 'works when passing nil' do
         | 
| 88 | 
            +
                  documents = @api.form('everything').page(nil).submit(@master_ref)
         | 
| 89 89 | 
             
                  documents.page.should == 1
         | 
| 90 90 | 
             
                  documents.results_per_page.should == 20
         | 
| 91 91 | 
             
                  documents.results_size.should == 20
         | 
| 92 92 | 
             
                  documents.total_results_size.should == 40
         | 
| 93 93 | 
             
                  documents.total_pages.should == 2
         | 
| 94 | 
            -
                  documents.next_page.should ==  | 
| 94 | 
            +
                  documents.next_page.should == 'https://lesbonneschoses.cdn.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=20'
         | 
| 95 95 | 
             
                  documents.prev_page.should == nil
         | 
| 96 96 | 
             
                end
         | 
| 97 97 | 
             
              end
         | 
| 98 98 |  | 
| 99 99 | 
             
              describe 'API::Document' do
         | 
| 100 100 | 
             
                before do
         | 
| 101 | 
            -
                  @document = @api.form('everything').query( | 
| 101 | 
            +
                  @document = @api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbh")]]').submit(@master_ref)[0]
         | 
| 102 102 | 
             
                end
         | 
| 103 103 |  | 
| 104 104 | 
             
                it 'Operator [] works on document' do
         | 
| @@ -112,7 +112,7 @@ describe 'LesBonnesChoses' do | |
| 112 112 | 
             
                it 'Operator [] raises error if field is nonsense' do
         | 
| 113 113 | 
             
                  expect {
         | 
| 114 114 | 
             
                    @document['blablabla']
         | 
| 115 | 
            -
                  }.to raise_error(ArgumentError,  | 
| 115 | 
            +
                  }.to raise_error(ArgumentError, 'Argument should contain one dot. Example: product.price')
         | 
| 116 116 | 
             
                end
         | 
| 117 117 | 
             
              end
         | 
| 118 118 |  | 
| @@ -138,6 +138,17 @@ describe 'LesBonnesChoses' do | |
| 138 138 | 
             
                end
         | 
| 139 139 | 
             
              end
         | 
| 140 140 |  | 
| 141 | 
            +
              describe 'FetchLinks' do
         | 
| 142 | 
            +
                it 'Fetches additional data with DocumentLink' do
         | 
| 143 | 
            +
                  documents = @api.form('everything')
         | 
| 144 | 
            +
                    .query(Prismic::Predicates::at('document.id', 'UlfoxUnM0wkXYXbt'))
         | 
| 145 | 
            +
                    .fetch_links('blog-post.author')
         | 
| 146 | 
            +
                    .submit(@master_ref).results
         | 
| 147 | 
            +
                  link = documents[0].get('blog-post.relatedpost')[0]
         | 
| 148 | 
            +
                  link.get_text('blog-post.author').value.should == 'John M. Martelle, Fine Pastry Magazine'
         | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
              end
         | 
| 151 | 
            +
             | 
| 141 152 | 
             
              describe 'Fragments' do
         | 
| 142 153 | 
             
                before do
         | 
| 143 154 | 
             
                  @link_resolver = Prismic.link_resolver("master"){|doc_link| "http://localhost/#{doc_link.id}" }
         | 
| @@ -158,7 +169,7 @@ describe 'LesBonnesChoses' do | |
| 158 169 | 
             
                        "<p>A lot of people touch base with us to know about one of our key ingredients, and the essential role it plays in our creations: ganache.</p>\n\n"\
         | 
| 159 170 | 
             
                        "<p>Indeed, ganache is the macaron's softener, or else, macarons would be but tough biscuits; it is the cupcake's wrapper, or else, cupcakes would be but plain old cake. We even sometimes use ganache within our cupcakes, to soften the cake itself, or as a support to our pies' content.</p>\n\n"\
         | 
| 160 171 | 
             
                        "<h2>How to approach ganache</h2>\n\n"\
         | 
| 161 | 
            -
                        "<p class=\"block-img\"><img src=\"https:// | 
| 172 | 
            +
                        "<p class=\"block-img\"><img src=\"https://lesbonneschoses.cdn.prismic.io/lesbonneschoses/ee7b984b98db4516aba2eabd54ab498293913c6c.jpg\" alt=\"\" width=\"640\" height=\"425\" /></p>\n\n"\
         | 
| 162 173 | 
             
                        "<p>Apart from the taste balance, which is always a challenge when it comes to pastry, the tough part about ganache is about thickness. It is even harder to predict through all the phases the ganache gets to meet (how long will it get melted? how long will it remain in the fridge?). "\
         | 
| 163 174 | 
             
                        "Things get a hell of a lot easier to get once you consider that there are two main ways to get the perfect ganache:</p>\n\n"\
         | 
| 164 175 | 
             
                        "<ul><li><strong>working from the top down</strong>: start with a thick, almost hard material, and soften it by manipulating it, or by mixing it with a more liquid ingredient (like milk)</li>"\
         | 
| @@ -180,7 +191,7 @@ describe 'LesBonnesChoses' do | |
| 180 191 | 
             
                          "<p>As a child, Jean-Michel Pastranova learned the art of fine cuisine from his grand-father, Jacques Pastranova, who was the creator of the "taste-design" art current, and still today an unmissable reference of forward-thinking in cuisine. At first an assistant in his grand-father's kitchen, Jean-Michel soon found himself fascinated by sweet flavors and the tougher art of pastry, drawing his own path in the ever-changing cuisine world.</p>\n\n"\
         | 
| 181 192 | 
             
                          "<p>In 1992, the first Les Bonnes Choses store opened on rue Saint-Lazare, in Paris (<a href=\"http://localhost/UlfoxUnM0wkXYXbb\">we're still there!</a>), much to everyone's surprise; indeed, back then, it was very surprising for a highly promising young man with a preordained career as a restaurant chef, to open a pastry shop instead. But soon enough, contemporary chefs understood that Jean-Michel had the drive to redefine a new nobility to pastry, the same way many other kinds of cuisine were being qualified as "fine".</p>\n\n"\
         | 
| 182 193 | 
             
                          "<p>In 1996, meeting an overwhelming demand, Jean-Michel Pastranova opened <a href=\"http://localhost/UlfoxUnM0wkXYXbP\">a second shop on Paris's Champs-Élysées</a>, and <a href=\"http://localhost/UlfoxUnM0wkXYXbr\">a third one in London</a>, the same week! Eventually, Les Bonnes Choses gained an international reputation as "a perfection so familiar and new at the same time, that it will feel like a taste travel" (New York Gazette), "the finest balance between surprise and comfort, enveloped in sweetness" (The Tokyo Tribune), "a renewal of the pastry genre (...), the kind that changed the way pastry is approached globally" (The San Francisco Gourmet News). Therefore, it was only a matter of time before Les Bonnes Choses opened shops in <a href=\"http://localhost/UlfoxUnM0wkXYXbc\">New York</a> (2000) and <a href=\"http://localhost/UlfoxUnM0wkXYXbU\">Tokyo</a> (2004).</p>\n\n"\
         | 
| 183 | 
            -
                          "<p>In 2013, Jean-Michel Pastranova stepped down as the CEO and Director of Workshops, remaining a senior advisor to the board and to the workshop artists; he passed the light on to Selena, his daugther, who initially learned the art of pastry from him. Passion for great food runs in the Pastranova family...</p>\n\n<img src=\"https:// | 
| 194 | 
            +
                          "<p>In 2013, Jean-Michel Pastranova stepped down as the CEO and Director of Workshops, remaining a senior advisor to the board and to the workshop artists; he passed the light on to Selena, his daugther, who initially learned the art of pastry from him. Passion for great food runs in the Pastranova family...</p>\n\n<img src=\"https://lesbonneschoses.cdn.prismic.io/lesbonneschoses/df6c1d87258a5bfadf3479b163fd85c829a5c0b8.jpg\" alt=\"\" width=\"800\" height=\"533\" />\n\n"\
         | 
| 184 195 | 
             
                          "<h2>Our main value: our customers' delight</h2>\n\n"\
         | 
| 185 196 | 
             
                          "<p>Our every action is driven by the firm belief that there is art in pastry, and that this art is one of the dearest pleasures one can experience.</p>\n\n"\
         | 
| 186 197 | 
             
                          "<p>At Les Bonnes Choses, people preparing your macarons are not simply "pastry chefs": they are "<a href=\"http://localhost/UlfoxUnM0wkXYXba\">ganache specialists</a>", "<a href=\"http://localhost/UlfoxUnM0wkXYXbQ\">fruit experts</a>", or "<a href=\"http://localhost/UlfoxUnM0wkXYXbn\">oven instrumentalists</a>". They are the best people out there to perform the tasks they perform to create your pastry, giving it the greatest value. And they just love to make their specialized pastry skill better and better until perfection.</p>\n\n"\
         | 
| @@ -196,7 +207,7 @@ describe 'LesBonnesChoses' do | |
| 196 207 | 
             
                          "<p>As a child, Jean-Michel Pastranova learned the art of fine cuisine from his grand-father, Jacques Pastranova, who was the creator of the "taste-design" art current, and still today an unmissable reference of forward-thinking in cuisine. At first an assistant in his grand-father's kitchen, Jean-Michel soon found himself fascinated by sweet flavors and the tougher art of pastry, drawing his own path in the ever-changing cuisine world.</p>\n\n"\
         | 
| 197 208 | 
             
                          "<p>In 1992, the first Les Bonnes Choses store opened on rue Saint-Lazare, in Paris (<a href=\"http://localhost/UlfoxUnM0wkXYXbb\">we're still there!</a>), much to everyone's surprise; indeed, back then, it was very surprising for a highly promising young man with a preordained career as a restaurant chef, to open a pastry shop instead. But soon enough, contemporary chefs understood that Jean-Michel had the drive to redefine a new nobility to pastry, the same way many other kinds of cuisine were being qualified as "fine".</p>\n\n"\
         | 
| 198 209 | 
             
                          "<p>In 1996, meeting an overwhelming demand, Jean-Michel Pastranova opened <a href=\"http://localhost/UlfoxUnM0wkXYXbP\">a second shop on Paris's Champs-Élysées</a>, and <a href=\"http://localhost/UlfoxUnM0wkXYXbr\">a third one in London</a>, the same week! Eventually, Les Bonnes Choses gained an international reputation as "a perfection so familiar and new at the same time, that it will feel like a taste travel" (New York Gazette), "the finest balance between surprise and comfort, enveloped in sweetness" (The Tokyo Tribune), "a renewal of the pastry genre (...), the kind that changed the way pastry is approached globally" (The San Francisco Gourmet News). Therefore, it was only a matter of time before Les Bonnes Choses opened shops in <a href=\"http://localhost/UlfoxUnM0wkXYXbc\">New York</a> (2000) and <a href=\"http://localhost/UlfoxUnM0wkXYXbU\">Tokyo</a> (2004).</p>\n\n"\
         | 
| 199 | 
            -
                          "<p>In 2013, Jean-Michel Pastranova stepped down as the CEO and Director of Workshops, remaining a senior advisor to the board and to the workshop artists; he passed the light on to Selena, his daugther, who initially learned the art of pastry from him. Passion for great food runs in the Pastranova family...</p>\n\n<p class=\"block-img\"><img src=\"https:// | 
| 210 | 
            +
                          "<p>In 2013, Jean-Michel Pastranova stepped down as the CEO and Director of Workshops, remaining a senior advisor to the board and to the workshop artists; he passed the light on to Selena, his daugther, who initially learned the art of pastry from him. Passion for great food runs in the Pastranova family...</p>\n\n<p class=\"block-img\"><img src=\"https://lesbonneschoses.cdn.prismic.io/lesbonneschoses/df6c1d87258a5bfadf3479b163fd85c829a5c0b8.jpg\" alt=\"\" width=\"800\" height=\"533\" /></p>\n\n"\
         | 
| 200 211 | 
             
                          "<h2>Our main value: our customers' delight</h2>\n\n"\
         | 
| 201 212 | 
             
                          "<p>Our every action is driven by the firm belief that there is art in pastry, and that this art is one of the dearest pleasures one can experience.</p>\n\n"\
         | 
| 202 213 | 
             
                          "<p>At Les Bonnes Choses, people preparing your macarons are not simply "pastry chefs": they are "<a href=\"http://localhost/UlfoxUnM0wkXYXba\">ganache specialists</a>", "<a href=\"http://localhost/UlfoxUnM0wkXYXbQ\">fruit experts</a>", or "<a href=\"http://localhost/UlfoxUnM0wkXYXbn\">oven instrumentalists</a>". They are the best people out there to perform the tasks they perform to create your pastry, giving it the greatest value. And they just love to make their specialized pastry skill better and better until perfection.</p>\n\n"\
         | 
    
        data/spec/prismic_spec.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ require 'spec_helper' | |
| 4 4 | 
             
            describe 'Api' do
         | 
| 5 5 | 
             
              before do
         | 
| 6 6 | 
             
                json_representation = '{"foo": "bar"}'
         | 
| 7 | 
            -
                @oauth_initiate_url = 'https://lesbonneschoses.prismic.io/auth'
         | 
| 7 | 
            +
                @oauth_initiate_url = 'https://lesbonneschoses.cdn.prismic.io/auth'
         | 
| 8 8 | 
             
                @api = Prismic::API.new(json_representation, nil, Prismic::DefaultHTTPClient, false){|api|
         | 
| 9 9 | 
             
                  api.bookmarks = {}
         | 
| 10 10 | 
             
                  api.tags = {}
         | 
| @@ -24,91 +24,91 @@ describe 'Api' do | |
| 24 24 | 
             
                    'form3' => Prismic::Form.new(@api, 'form3', {}, nil, nil, nil, nil),
         | 
| 25 25 | 
             
                    'form4' => Prismic::Form.new(@api, 'form4', {}, nil, nil, nil, nil),
         | 
| 26 26 | 
             
                  }
         | 
| 27 | 
            -
                  api.oauth =  Prismic::API::OAuth.new(@oauth_initiate_url,  | 
| 27 | 
            +
                  api.oauth =  Prismic::API::OAuth.new(@oauth_initiate_url, 'https://lesbonneschoses.cdn.prismic.io/auth/token', Prismic::DefaultHTTPClient)
         | 
| 28 28 | 
             
                }
         | 
| 29 29 | 
             
              end
         | 
| 30 30 |  | 
| 31 31 | 
             
              describe 'id' do
         | 
| 32 | 
            -
                it  | 
| 32 | 
            +
                it 'returns the right id' do
         | 
| 33 33 | 
             
                  @api.ref('key1').id.should == 'id1'
         | 
| 34 34 | 
             
                end
         | 
| 35 35 | 
             
              end
         | 
| 36 36 |  | 
| 37 37 | 
             
              describe 'ref' do
         | 
| 38 | 
            -
                it  | 
| 38 | 
            +
                it 'returns the right Ref' do
         | 
| 39 39 | 
             
                  @api.ref('key2').label.should == 'label2'
         | 
| 40 40 | 
             
                end
         | 
| 41 41 | 
             
              end
         | 
| 42 42 |  | 
| 43 43 | 
             
              describe 'refs' do
         | 
| 44 | 
            -
                it  | 
| 44 | 
            +
                it 'returns the correct number of elements' do
         | 
| 45 45 | 
             
                  @api.refs.size.should == 4
         | 
| 46 46 | 
             
                end
         | 
| 47 47 | 
             
              end
         | 
| 48 48 |  | 
| 49 49 | 
             
              describe 'ref_id_by_label' do
         | 
| 50 | 
            -
                it  | 
| 50 | 
            +
                it 'returns the id of the ref' do
         | 
| 51 51 | 
             
                  @api.ref('key4').ref == 'ref4'
         | 
| 52 52 | 
             
                end
         | 
| 53 53 | 
             
              end
         | 
| 54 54 |  | 
| 55 55 | 
             
              describe 'master_ref' do
         | 
| 56 | 
            -
                it  | 
| 56 | 
            +
                it 'returns the right Ref' do
         | 
| 57 57 | 
             
                  @api.master_ref.label.should == 'label3'
         | 
| 58 58 | 
             
                end
         | 
| 59 59 | 
             
              end
         | 
| 60 60 |  | 
| 61 61 | 
             
              describe 'master' do
         | 
| 62 | 
            -
                it  | 
| 62 | 
            +
                it 'returns the right Ref' do
         | 
| 63 63 | 
             
                  @api.master.label.should == 'label3'
         | 
| 64 64 | 
             
                end
         | 
| 65 65 | 
             
              end
         | 
| 66 66 |  | 
| 67 67 | 
             
              describe 'forms' do
         | 
| 68 | 
            -
                it  | 
| 68 | 
            +
                it 'return the right Form' do
         | 
| 69 69 | 
             
                  @api.forms['form2'].name.should == 'form2'
         | 
| 70 70 | 
             
                end
         | 
| 71 71 | 
             
              end
         | 
| 72 72 |  | 
| 73 73 | 
             
              describe 'create_search_form' do
         | 
| 74 | 
            -
                it  | 
| 74 | 
            +
                it 'create a new search form for the right form' do
         | 
| 75 75 | 
             
                  @form = @api.form('form2')
         | 
| 76 76 | 
             
                  @form.form.name.should == 'form2'
         | 
| 77 77 | 
             
                end
         | 
| 78 | 
            -
                it  | 
| 78 | 
            +
                it 'store default value as simple value when the field is not repeatable' do
         | 
| 79 79 | 
             
                  @form = @api.form('form2')
         | 
| 80 80 | 
             
                  @form.data['param1'].should == 'value1'
         | 
| 81 81 | 
             
                end
         | 
| 82 | 
            -
                it  | 
| 82 | 
            +
                it 'store default value as array when the field is repeatable' do
         | 
| 83 83 | 
             
                  @form = @api.form('form2')
         | 
| 84 84 | 
             
                  @form.data['q'].should == ['[[any(document.type, [\"product\"])]]']
         | 
| 85 85 | 
             
                end
         | 
| 86 86 | 
             
              end
         | 
| 87 87 |  | 
| 88 88 | 
             
              describe 'deprecated create_search_form' do
         | 
| 89 | 
            -
                it  | 
| 90 | 
            -
                  @api.should_receive(:warn).with( | 
| 89 | 
            +
                it 'create a new search form for the right form' do
         | 
| 90 | 
            +
                  @api.should_receive(:warn).with('[DEPRECATION] `create_search_form` is deprecated.  Please use `form` instead.')
         | 
| 91 91 | 
             
                  @form = @api.create_search_form('form2')
         | 
| 92 92 | 
             
                  @form.form.name.should == 'form2'
         | 
| 93 93 | 
             
                end
         | 
| 94 | 
            -
                it  | 
| 94 | 
            +
                it 'store default value as simple value when the field is not repeatable' do
         | 
| 95 95 | 
             
                  @form = @api.create_search_form('form2')
         | 
| 96 96 | 
             
                  @form.data['param1'].should == 'value1'
         | 
| 97 97 | 
             
                end
         | 
| 98 | 
            -
                it  | 
| 98 | 
            +
                it 'store default value as array when the field is repeatable' do
         | 
| 99 99 | 
             
                  @form = @api.create_search_form('form2')
         | 
| 100 100 | 
             
                  @form.data['q'].should == ['[[any(document.type, [\"product\"])]]']
         | 
| 101 101 | 
             
                end
         | 
| 102 102 | 
             
              end
         | 
| 103 103 |  | 
| 104 104 | 
             
              describe 'forms' do
         | 
| 105 | 
            -
                it  | 
| 105 | 
            +
                it 'returns the correct number of elements' do
         | 
| 106 106 | 
             
                  @api.forms.size.should == 4
         | 
| 107 107 | 
             
                end
         | 
| 108 108 | 
             
              end
         | 
| 109 109 |  | 
| 110 110 | 
             
              describe 'master' do
         | 
| 111 | 
            -
                it  | 
| 111 | 
            +
                it 'returns a master Ref' do
         | 
| 112 112 | 
             
                  @api.master.master?.should be_true
         | 
| 113 113 | 
             
                end
         | 
| 114 114 | 
             
              end
         | 
| @@ -120,19 +120,19 @@ describe 'Api' do | |
| 120 120 | 
             
                  @parsed = Prismic::API.parse_api_response(@json, nil, Prismic::DefaultHTTPClient, false)
         | 
| 121 121 | 
             
                end
         | 
| 122 122 |  | 
| 123 | 
            -
                it  | 
| 123 | 
            +
                it 'does not allow to be created without master Ref' do
         | 
| 124 124 | 
             
                  expect {
         | 
| 125 | 
            -
                    Prismic::API.parse_api_response({ | 
| 126 | 
            -
                  }.to raise_error(Prismic::API::BadPrismicResponseError,  | 
| 125 | 
            +
                    Prismic::API.parse_api_response({'refs' => []}, nil, Prismic::DefaultHTTPClient, false)
         | 
| 126 | 
            +
                  }.to raise_error(Prismic::API::BadPrismicResponseError, 'No master Ref found')
         | 
| 127 127 | 
             
                end
         | 
| 128 128 |  | 
| 129 | 
            -
                it  | 
| 129 | 
            +
                it 'does not allow to be created without any Ref' do
         | 
| 130 130 | 
             
                  expect {
         | 
| 131 131 | 
             
                    Prismic::API.parse_api_response({}, nil, Prismic::DefaultHTTPClient, false)
         | 
| 132 | 
            -
                  }.to raise_error(Prismic::API::BadPrismicResponseError,  | 
| 132 | 
            +
                  }.to raise_error(Prismic::API::BadPrismicResponseError, 'No refs given')
         | 
| 133 133 | 
             
                end
         | 
| 134 134 |  | 
| 135 | 
            -
                it  | 
| 135 | 
            +
                it 'creates 2 refs' do
         | 
| 136 136 | 
             
                  @parsed.refs.size.should == 2
         | 
| 137 137 | 
             
                end
         | 
| 138 138 |  | 
| @@ -148,31 +148,31 @@ describe 'Api' do | |
| 148 148 | 
             
                  @parsed.refs['bar'].master?.should == false
         | 
| 149 149 | 
             
                end
         | 
| 150 150 |  | 
| 151 | 
            -
                it  | 
| 151 | 
            +
                it 'creates 3 bookmarks' do
         | 
| 152 152 | 
             
                  @parsed.bookmarks.size.should == 3
         | 
| 153 153 | 
             
                end
         | 
| 154 154 |  | 
| 155 | 
            -
                it  | 
| 155 | 
            +
                it 'creates the right bookmarks' do
         | 
| 156 156 | 
             
                  @parsed.bookmarks['about'].should == 'Ue0EDd_mqb8Dhk3j'
         | 
| 157 157 | 
             
                end
         | 
| 158 158 |  | 
| 159 | 
            -
                it  | 
| 159 | 
            +
                it 'creates 6 types' do
         | 
| 160 160 | 
             
                  @parsed.types.size.should == 6
         | 
| 161 161 | 
             
                end
         | 
| 162 162 |  | 
| 163 | 
            -
                it  | 
| 163 | 
            +
                it 'creates the right types' do
         | 
| 164 164 | 
             
                  @parsed.types['blog-post'].should == 'Blog post'
         | 
| 165 165 | 
             
                end
         | 
| 166 166 |  | 
| 167 | 
            -
                it  | 
| 167 | 
            +
                it 'creates 4 tags' do
         | 
| 168 168 | 
             
                  @parsed.tags.size.should == 4
         | 
| 169 169 | 
             
                end
         | 
| 170 170 |  | 
| 171 | 
            -
                it  | 
| 171 | 
            +
                it 'creates the right tags' do
         | 
| 172 172 | 
             
                  @parsed.tags.should include 'Cupcake'
         | 
| 173 173 | 
             
                end
         | 
| 174 174 |  | 
| 175 | 
            -
                it  | 
| 175 | 
            +
                it 'creates 10 forms' do
         | 
| 176 176 | 
             
                  @parsed.forms.size.should == 10
         | 
| 177 177 | 
             
                end
         | 
| 178 178 |  | 
| @@ -193,18 +193,18 @@ describe 'Api' do | |
| 193 193 | 
             
                end
         | 
| 194 194 |  | 
| 195 195 | 
             
                it "creates the right form's action" do
         | 
| 196 | 
            -
                  @parsed.forms['pies'].action.should == 'http://lesbonneschoses.prismic.io/api/documents/search'
         | 
| 196 | 
            +
                  @parsed.forms['pies'].action.should == 'http://lesbonneschoses.cdn.prismic.io/api/documents/search'
         | 
| 197 197 | 
             
                end
         | 
| 198 198 |  | 
| 199 | 
            -
                it  | 
| 199 | 
            +
                it 'creates forms with the right fields' do
         | 
| 200 200 | 
             
                  @parsed.forms['pies'].fields.size.should == 2
         | 
| 201 201 | 
             
                end
         | 
| 202 202 |  | 
| 203 | 
            -
                it  | 
| 203 | 
            +
                it 'creates forms with the right type info' do
         | 
| 204 204 | 
             
                  @parsed.forms['pies'].fields['ref'].field_type.should == 'String'
         | 
| 205 205 | 
             
                end
         | 
| 206 206 |  | 
| 207 | 
            -
                it  | 
| 207 | 
            +
                it 'creates forms with the right default info' do
         | 
| 208 208 | 
             
                  @parsed.forms['pies'].fields['q'].default.should ==
         | 
| 209 209 | 
             
                    '[[at(document.tags, ["Pie"])][any(document.type, ["product"])]]'
         | 
| 210 210 | 
             
                end
         | 
| @@ -224,33 +224,33 @@ describe 'Api' do | |
| 224 224 | 
             
                  @json = @api.as_json
         | 
| 225 225 | 
             
                end
         | 
| 226 226 |  | 
| 227 | 
            -
                it  | 
| 227 | 
            +
                it 'returns the json representation of the api' do
         | 
| 228 228 | 
             
                  JSON.load(@json)['foo'].should == 'bar'
         | 
| 229 229 | 
             
                end
         | 
| 230 230 |  | 
| 231 | 
            -
                it  | 
| 231 | 
            +
                it 'returns the json representation of the api containing one single element' do
         | 
| 232 232 | 
             
                  JSON.load(@json).size.should == 1
         | 
| 233 233 | 
             
                end
         | 
| 234 234 | 
             
              end
         | 
| 235 235 |  | 
| 236 | 
            -
              describe  | 
| 236 | 
            +
              describe 'oauth_initiate_url' do
         | 
| 237 237 | 
             
                before do
         | 
| 238 | 
            -
                  @client_id =  | 
| 239 | 
            -
                  @redirect_uri =  | 
| 240 | 
            -
                  @scope =  | 
| 238 | 
            +
                  @client_id = 'client_id'
         | 
| 239 | 
            +
                  @redirect_uri = 'http://website/callback'
         | 
| 240 | 
            +
                  @scope = 'none'
         | 
| 241 241 | 
             
                end
         | 
| 242 242 | 
             
                def oauth_initiate_url
         | 
| 243 | 
            -
                  Prismic.oauth_initiate_url( | 
| 243 | 
            +
                  Prismic.oauth_initiate_url('https://lesbonneschoses.cdn.prismic.io/api', {
         | 
| 244 244 | 
             
                    client_id: @client_id,
         | 
| 245 245 | 
             
                    redirect_uri: @redirect_uri,
         | 
| 246 | 
            -
                    scope: @scope | 
| 246 | 
            +
                    scope: @scope
         | 
| 247 247 | 
             
                  })
         | 
| 248 248 | 
             
                end
         | 
| 249 249 | 
             
                def redirect_uri_encoded
         | 
| 250 250 | 
             
                  CGI.escape(@redirect_uri)
         | 
| 251 251 | 
             
                end
         | 
| 252 | 
            -
                it  | 
| 253 | 
            -
                  oauth_initiate_url.should == " | 
| 252 | 
            +
                it 'build a valid url' do
         | 
| 253 | 
            +
                  oauth_initiate_url.should == "https://lesbonneschoses.prismic.io/auth?client_id=#@client_id&redirect_uri=#{redirect_uri_encoded}&scope=#@scope"
         | 
| 254 254 | 
             
                end
         | 
| 255 255 | 
             
              end
         | 
| 256 256 |  | 
| @@ -258,19 +258,19 @@ end | |
| 258 258 |  | 
| 259 259 | 
             
            describe 'LinkResolver' do
         | 
| 260 260 | 
             
              before do
         | 
| 261 | 
            -
                @doc_link = Prismic::Fragments::DocumentLink.new('id', 'blog-post', ['tag1', 'tag2'], 'my-slug', false)
         | 
| 262 | 
            -
                @document = Prismic::Document.new('id', 'blog-post', nil, ['tag1', 'tag2'], ['my-slug', 'my-other-slug'], nil | 
| 261 | 
            +
                @doc_link = Prismic::Fragments::DocumentLink.new('id', nil, 'blog-post', ['tag1', 'tag2'], 'my-slug', {}, false)
         | 
| 262 | 
            +
                @document = Prismic::Document.new('id', nil, 'blog-post', nil, ['tag1', 'tag2'], ['my-slug', 'my-other-slug'], nil)
         | 
| 263 263 |  | 
| 264 264 | 
             
                @link_resolver = Prismic::LinkResolver.new(nil) do |doc|
         | 
| 265 265 | 
             
                  '/'+doc.link_type+'/'+doc.id+'/'+doc.slug
         | 
| 266 266 | 
             
                end
         | 
| 267 267 | 
             
              end
         | 
| 268 268 |  | 
| 269 | 
            -
              it  | 
| 269 | 
            +
              it 'builds the right URL from a DocumentLink' do
         | 
| 270 270 | 
             
                @link_resolver.link_to(@doc_link).should == '/blog-post/id/my-slug'
         | 
| 271 271 | 
             
              end
         | 
| 272 272 |  | 
| 273 | 
            -
              it  | 
| 273 | 
            +
              it 'builds the right URL from a Document' do
         | 
| 274 274 | 
             
                @link_resolver.link_to(@document).should == '/blog-post/id/my-slug'
         | 
| 275 275 | 
             
              end
         | 
| 276 276 | 
             
            end
         | 
| @@ -278,45 +278,45 @@ end | |
| 278 278 | 
             
            describe 'Document' do
         | 
| 279 279 | 
             
              before do
         | 
| 280 280 | 
             
                fragments = {
         | 
| 281 | 
            -
                  'field1' => Prismic::Fragments::DocumentLink.new(nil, nil, nil, nil, nil),
         | 
| 281 | 
            +
                  'field1' => Prismic::Fragments::DocumentLink.new(nil, nil, nil, nil, nil, {}, nil),
         | 
| 282 282 | 
             
                  'field2' => Prismic::Fragments::WebLink.new('weburl')
         | 
| 283 283 | 
             
                }
         | 
| 284 | 
            -
                @document = Prismic::Document.new(nil, nil, nil, nil, ['my-slug'],  | 
| 284 | 
            +
                @document = Prismic::Document.new(nil, nil, nil, nil, nil, ['my-slug'], fragments)
         | 
| 285 285 | 
             
                @link_resolver = Prismic::LinkResolver.new('master'){|doc_link|
         | 
| 286 286 | 
             
                  "http://host/#{doc_link.id}"
         | 
| 287 287 | 
             
                }
         | 
| 288 288 | 
             
              end
         | 
| 289 289 |  | 
| 290 290 | 
             
              describe 'first_title' do
         | 
| 291 | 
            -
                it  | 
| 291 | 
            +
                it 'returns the right title' do
         | 
| 292 292 | 
             
                  @document.fragments['field3'] = Prismic::Fragments::StructuredText.new([
         | 
| 293 | 
            -
                    Prismic::Fragments::StructuredText::Block::Text.new( | 
| 294 | 
            -
                    Prismic::Fragments::StructuredText::Block::Heading.new( | 
| 295 | 
            -
                    Prismic::Fragments::StructuredText::Block::Heading.new( | 
| 296 | 
            -
                    Prismic::Fragments::StructuredText::Block::Text.new( | 
| 293 | 
            +
                    Prismic::Fragments::StructuredText::Block::Text.new('This is not a title', []),
         | 
| 294 | 
            +
                    Prismic::Fragments::StructuredText::Block::Heading.new('This is a title, but not the highest', [], 3),
         | 
| 295 | 
            +
                    Prismic::Fragments::StructuredText::Block::Heading.new('This is the highest title of the fragment, but not the document', [], 2),
         | 
| 296 | 
            +
                    Prismic::Fragments::StructuredText::Block::Text.new('This is not a title', [])
         | 
| 297 297 | 
             
                  ])
         | 
| 298 298 | 
             
                  @document.fragments['field4'] = Prismic::Fragments::StructuredText.new([
         | 
| 299 | 
            -
                    Prismic::Fragments::StructuredText::Block::Text.new( | 
| 300 | 
            -
                    Prismic::Fragments::StructuredText::Block::Heading.new( | 
| 301 | 
            -
                    Prismic::Fragments::StructuredText::Block::Heading.new( | 
| 302 | 
            -
                    Prismic::Fragments::StructuredText::Block::Text.new( | 
| 299 | 
            +
                    Prismic::Fragments::StructuredText::Block::Text.new('This is not a title', []),
         | 
| 300 | 
            +
                    Prismic::Fragments::StructuredText::Block::Heading.new('This is a title, but not the highest', [], 3),
         | 
| 301 | 
            +
                    Prismic::Fragments::StructuredText::Block::Heading.new('This is the highest title of the document', [], 1),
         | 
| 302 | 
            +
                    Prismic::Fragments::StructuredText::Block::Text.new('This is not a title', [])
         | 
| 303 303 | 
             
                  ])
         | 
| 304 304 | 
             
                  @document.fragments['field5'] = Prismic::Fragments::StructuredText.new([
         | 
| 305 | 
            -
                    Prismic::Fragments::StructuredText::Block::Text.new( | 
| 306 | 
            -
                    Prismic::Fragments::StructuredText::Block::Heading.new( | 
| 307 | 
            -
                    Prismic::Fragments::StructuredText::Block::Heading.new( | 
| 308 | 
            -
                    Prismic::Fragments::StructuredText::Block::Text.new( | 
| 305 | 
            +
                    Prismic::Fragments::StructuredText::Block::Text.new('This is not a title', []),
         | 
| 306 | 
            +
                    Prismic::Fragments::StructuredText::Block::Heading.new('This is a title, but not the highest', [], 3),
         | 
| 307 | 
            +
                    Prismic::Fragments::StructuredText::Block::Heading.new('This is the highest title of the fragment, but not the document', [], 2),
         | 
| 308 | 
            +
                    Prismic::Fragments::StructuredText::Block::Text.new('This is not a title', [])
         | 
| 309 309 | 
             
                  ])
         | 
| 310 | 
            -
                  @document.first_title.should ==  | 
| 310 | 
            +
                  @document.first_title.should == 'This is the highest title of the document'
         | 
| 311 311 | 
             
                end
         | 
| 312 312 |  | 
| 313 | 
            -
                it  | 
| 313 | 
            +
                it 'returns false if no title' do
         | 
| 314 314 | 
             
                  @document.first_title.should == false
         | 
| 315 315 | 
             
                end
         | 
| 316 316 | 
             
              end
         | 
| 317 317 |  | 
| 318 318 | 
             
              describe 'slug' do
         | 
| 319 | 
            -
                it  | 
| 319 | 
            +
                it 'returns the first slug if found' do
         | 
| 320 320 | 
             
                  @document.slug.should == 'my-slug'
         | 
| 321 321 | 
             
                end
         | 
| 322 322 |  | 
| @@ -327,7 +327,7 @@ describe 'Document' do | |
| 327 327 | 
             
              end
         | 
| 328 328 |  | 
| 329 329 | 
             
              describe 'as_html' do
         | 
| 330 | 
            -
                it  | 
| 330 | 
            +
                it 'returns a <section> HTML element' do
         | 
| 331 331 | 
             
                  Nokogiri::XML(@document.as_html(@link_resolver)).child.name.should == 'section'
         | 
| 332 332 | 
             
                end
         | 
| 333 333 |  | 
| @@ -354,47 +354,49 @@ describe 'SearchForm' do | |
| 354 354 |  | 
| 355 355 | 
             
              describe 'fields methods' do
         | 
| 356 356 |  | 
| 357 | 
            -
                it  | 
| 357 | 
            +
                it 'should be created for each valid field names' do
         | 
| 358 358 | 
             
                  @form = create_form('a_param' => @field)
         | 
| 359 359 | 
             
                  @form.should respond_to(:a_param)
         | 
| 360 360 | 
             
                end
         | 
| 361 361 |  | 
| 362 | 
            -
                it  | 
| 362 | 
            +
                it 'should be created for each valid field names with number' do
         | 
| 363 363 | 
             
                  @form = create_form('a_param2' => @field)
         | 
| 364 364 | 
             
                  @form.should respond_to(:a_param2)
         | 
| 365 365 | 
             
                end
         | 
| 366 366 |  | 
| 367 | 
            -
                it  | 
| 367 | 
            +
                it 'should be created for each camelCase field names' do
         | 
| 368 368 | 
             
                  @form = create_form('anExampleParam0A0B' => @field)
         | 
| 369 369 | 
             
                  @form.should respond_to(:an_example_param0_a0_b)
         | 
| 370 370 | 
             
                end
         | 
| 371 371 |  | 
| 372 | 
            -
                it  | 
| 372 | 
            +
                it 'should not be created for field names begining with a number' do
         | 
| 373 373 | 
             
                  @form = create_form('2param' => @field)
         | 
| 374 374 | 
             
                  @form.should_not respond_to(:'2param')
         | 
| 375 375 | 
             
                end
         | 
| 376 376 |  | 
| 377 | 
            -
                it  | 
| 377 | 
            +
                it 'should not be created for field names begining with an underscore' do
         | 
| 378 378 | 
             
                  @form = create_form('_param' => @field)
         | 
| 379 379 | 
             
                  @form.should_not respond_to(:'_param')
         | 
| 380 380 | 
             
                end
         | 
| 381 381 |  | 
| 382 | 
            -
                it  | 
| 382 | 
            +
                it 'should not be created for field names containing invalid characters' do
         | 
| 383 383 | 
             
                  @form = create_form('a-param' => @field)
         | 
| 384 384 | 
             
                  @form.should_not respond_to(:'a-param')
         | 
| 385 385 | 
             
                end
         | 
| 386 386 |  | 
| 387 | 
            -
                it  | 
| 388 | 
            -
                  Prismic::SearchForm.module_exec { def param_example_for_tests() | 
| 387 | 
            +
                it 'should not be created if a method with same name already exists' do
         | 
| 388 | 
            +
                  Prismic::SearchForm.module_exec { def param_example_for_tests()
         | 
| 389 | 
            +
                    'ok'
         | 
| 390 | 
            +
                  end }
         | 
| 389 391 | 
             
                  @form = create_form('param_example_for_tests' => @field)
         | 
| 390 | 
            -
                  @form.param_example_for_tests.should ==  | 
| 392 | 
            +
                  @form.param_example_for_tests.should == 'ok'
         | 
| 391 393 | 
             
                end
         | 
| 392 394 |  | 
| 393 395 | 
             
              end
         | 
| 394 396 |  | 
| 395 397 | 
             
              describe 'set() for queries' do
         | 
| 396 398 |  | 
| 397 | 
            -
                it  | 
| 399 | 
            +
                it 'append value for repeatable fields' do
         | 
| 398 400 | 
             
                  @field = Prismic::Field.new('String', 'foo', true)
         | 
| 399 401 | 
             
                  @form = create_form('q' => @field)
         | 
| 400 402 | 
             
                  @form.set('q', 'bar')
         | 
| @@ -403,7 +405,7 @@ describe 'SearchForm' do | |
| 403 405 | 
             
                  @form.data.should == { 'q' => ['foo', 'bar', 'baz'] }  # test an other
         | 
| 404 406 | 
             
                end
         | 
| 405 407 |  | 
| 406 | 
            -
                it  | 
| 408 | 
            +
                it 'replace value for non repeatable fields' do
         | 
| 407 409 | 
             
                  @field = Prismic::Field.new('String', 'foo', false)
         | 
| 408 410 | 
             
                  @form = create_form('q' => @field)
         | 
| 409 411 | 
             
                  @form.set('q', 'bar')
         | 
| @@ -412,26 +414,26 @@ describe 'SearchForm' do | |
| 412 414 | 
             
                  @form.data.should == { 'q' => 'baz' }  # test an other
         | 
| 413 415 | 
             
                end
         | 
| 414 416 |  | 
| 415 | 
            -
                it  | 
| 417 | 
            +
                it 'create value array for repeatable fields without value' do
         | 
| 416 418 | 
             
                  @field = Prismic::Field.new('String', nil, true)
         | 
| 417 419 | 
             
                  @form = create_form('q' => @field)
         | 
| 418 420 | 
             
                  @form.set('q', 'bar')
         | 
| 419 421 | 
             
                  @form.data.should == { 'q' => ['bar'] }
         | 
| 420 422 | 
             
                end
         | 
| 421 423 |  | 
| 422 | 
            -
                it  | 
| 424 | 
            +
                it 'create value for non repeatable fields without value' do
         | 
| 423 425 | 
             
                  @field = Prismic::Field.new('String', nil, false)
         | 
| 424 426 | 
             
                  @form = create_form('q' => @field)
         | 
| 425 427 | 
             
                  @form.set('q', 'bar')
         | 
| 426 428 | 
             
                  @form.data.should == { 'q' => 'bar' }
         | 
| 427 429 | 
             
                end
         | 
| 428 430 |  | 
| 429 | 
            -
                it  | 
| 431 | 
            +
                it 'returns the form itself' do
         | 
| 430 432 | 
             
                  @form = create_form('q' => @field)
         | 
| 431 433 | 
             
                  @form.query('foo').should equal @form
         | 
| 432 434 | 
             
                end
         | 
| 433 435 |  | 
| 434 | 
            -
                it  | 
| 436 | 
            +
                it 'merge user defined params into default ones' do
         | 
| 435 437 | 
             
                  field = ->(value){ Prismic::Field.new('String', value) }
         | 
| 436 438 | 
             
                  default_params = {'param1' => field.('a'), 'param2' => field.('b')}
         | 
| 437 439 | 
             
                  @form = create_form(default_params)
         | 
| @@ -441,88 +443,10 @@ describe 'SearchForm' do | |
| 441 443 | 
             
              end
         | 
| 442 444 |  | 
| 443 445 | 
             
              describe 'submit' do
         | 
| 444 | 
            -
                it  | 
| 446 | 
            +
                it 'raises an exception if no ref is set' do
         | 
| 445 447 | 
             
                  @form = create_form('q' => @field)
         | 
| 446 448 | 
             
                  expect { @form.submit }.to raise_error Prismic::SearchForm::NoRefSetException
         | 
| 447 449 | 
             
                end
         | 
| 448 450 | 
             
              end
         | 
| 449 451 |  | 
| 450 | 
            -
              describe 'submit_raw' do
         | 
| 451 | 
            -
                before do
         | 
| 452 | 
            -
                  @api = Prismic.api("https://lesbonneschoses.prismic.io/api")
         | 
| 453 | 
            -
                  @master_ref = @api.master_ref
         | 
| 454 | 
            -
                end
         | 
| 455 | 
            -
                it "returns a proper JSON string if all ok" do
         | 
| 456 | 
            -
                  data = <<-DATA.gsub(/\n */, '').strip
         | 
| 457 | 
            -
                    {
         | 
| 458 | 
            -
                      "page":1,
         | 
| 459 | 
            -
                      "results_per_page":1,
         | 
| 460 | 
            -
                      "results_size":1,
         | 
| 461 | 
            -
                      "total_results_size":40,
         | 
| 462 | 
            -
                      "total_pages":40,
         | 
| 463 | 
            -
                      "next_page":"https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=1",
         | 
| 464 | 
            -
                      "prev_page":null,
         | 
| 465 | 
            -
                      "results":[{
         | 
| 466 | 
            -
                        "id":"UlfoxUnM0wkXYXbV",
         | 
| 467 | 
            -
                        "type":"job-offer",
         | 
| 468 | 
            -
                        "href":"https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22UlfoxUnM0wkXYXbV%22%29+%5D%5D",
         | 
| 469 | 
            -
                        "tags":[],
         | 
| 470 | 
            -
                        "slugs":["art-director"],
         | 
| 471 | 
            -
                        "linked_documents":[{
         | 
| 472 | 
            -
                          "id":"UlfoxUnM0wkXYXbb",
         | 
| 473 | 
            -
                          "tags":[],
         | 
| 474 | 
            -
                          "type":"store",
         | 
| 475 | 
            -
                          "slug":"paris-saint-lazare"
         | 
| 476 | 
            -
                        }],
         | 
| 477 | 
            -
                        "data":{
         | 
| 478 | 
            -
                          "job-offer":{
         | 
| 479 | 
            -
                            "name":{
         | 
| 480 | 
            -
                              "type":"StructuredText",
         | 
| 481 | 
            -
                              "value":[{"type":"heading1","text":"Art Director","spans":[]}]
         | 
| 482 | 
            -
                            },
         | 
| 483 | 
            -
                            "location":[{
         | 
| 484 | 
            -
                              "type":"Link.document",
         | 
| 485 | 
            -
                              "value":{
         | 
| 486 | 
            -
                                "document":{
         | 
| 487 | 
            -
                                  "id":"UlfoxUnM0wkXYXbb",
         | 
| 488 | 
            -
                                  "type":"store",
         | 
| 489 | 
            -
                                  "tags":[],
         | 
| 490 | 
            -
                                  "slug":"paris-saint-lazare"
         | 
| 491 | 
            -
                                },
         | 
| 492 | 
            -
                                "isBroken":false
         | 
| 493 | 
            -
                              }
         | 
| 494 | 
            -
                            }],
         | 
| 495 | 
            -
                            "contract_type":{"type":"Select","value":"Permanent"},
         | 
| 496 | 
            -
                            "service":{"type":"Select","value":"Office"},
         | 
| 497 | 
            -
                            "profile":{
         | 
| 498 | 
            -
                              "type":"StructuredText",
         | 
| 499 | 
            -
                              "value":[{
         | 
| 500 | 
            -
                                "type":"paragraph",
         | 
| 501 | 
            -
                                "text":"Brand visual identity must be vital to you, and you must have a thorough experience with working for/with great visual brands. We will ask you to present your previous work, and explain your choices, so be prepared. Previous work with luxury brands is a plus.",
         | 
| 502 | 
            -
                                "spans":[]
         | 
| 503 | 
            -
                              }]
         | 
| 504 | 
            -
                            },
         | 
| 505 | 
            -
                            "job_description":{
         | 
| 506 | 
            -
                              "type":"StructuredText",
         | 
| 507 | 
            -
                              "value":[{
         | 
| 508 | 
            -
                                "type":"paragraph",
         | 
| 509 | 
            -
                                "text":"As our only Art director, you will be the one in charge of every design aspect of Les Bonnes Choses, from the design of our pastry boxes, of our shop fronts, of our website, ... You will lead a team of more specialized people, and you will be expected to be able to travel from time to time.",
         | 
| 510 | 
            -
                                "spans":[]
         | 
| 511 | 
            -
                              },{
         | 
| 512 | 
            -
                                "type":"paragraph",
         | 
| 513 | 
            -
                                "text":"You will be the vessel that will bring emotions to our clientbase, before they tasted our pastries. We are aware the responsibility is huge, and we hope that you are too.",
         | 
| 514 | 
            -
                                "spans":[]
         | 
| 515 | 
            -
                              }]
         | 
| 516 | 
            -
                            }
         | 
| 517 | 
            -
                          }
         | 
| 518 | 
            -
                        }
         | 
| 519 | 
            -
                      }],
         | 
| 520 | 
            -
                      "version":"61d96e9",
         | 
| 521 | 
            -
                      "license":"All Rights Reserved"
         | 
| 522 | 
            -
                    }
         | 
| 523 | 
            -
                  DATA
         | 
| 524 | 
            -
                  rx = Regexp.escape(data).sub(/"version":"[^"]+"/, '"version":"[^"]+"')
         | 
| 525 | 
            -
                  @api.form("everything").page_size('1').submit_raw(@master_ref).should =~ /#{rx}/
         | 
| 526 | 
            -
                end
         | 
| 527 | 
            -
              end
         | 
| 528 452 | 
             
            end
         |